Jump to content

subdomain always redirect to index.php??


robert_gsfame

Recommended Posts

I really confused with this....i wish to have a subdomain for my user but i always manage subdomain by typing *.domain.com inside my cpanel which is always redirect me to index.php

 

Is it possible to redirect all subdomain to http://www.domainname.com/page1.php instead of index.php???

 

Would be appreciate if you can give me brief explanation

 

thx so much!! ;D

Link to comment
Share on other sites

method 1: you have to set wildcard subdomains to another directory rather than public_html [Root]

 

eg . you can set it /public_html/subdomains

 

method 2: If because of some reasons you are using public_html

then

$exp = explode(".", $_SERVER['HTTP_HOST']) ;
  if($exp[0]== "www" || $exp[0] == "WWW")
{
$username = $exp[1];
if($username != "yourTLD")  //your main domain
{
header("Location:page1.php"); 
}
}
else
{
  $username = $exp[0];
  if($username != "yourTLD")  //your main domain
{
header("Location:page1.php");
}
}

Link to comment
Share on other sites

I use the second method but i have this error when using mozilla

The page isn't redirecting properly

Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

    *  This problem can sometimes be caused by disabling or refusing to accept

          cookies.

 

 

 

 

       

       

     

 

 

     

     

Link to comment
Share on other sites

yeah you're right i got wrongly loop!!

 

thanks SO MUCH for all helps  ;D

 

both of you're really great!!

 

One more thing, i redirect the page to http://www.domain.com/page1.php?user=$subdomain when subdomain was typed on url

 

Can i have only subdomain.domain.com typed instead of subdomain.domain.com/page1.php?user=$subdomain

using .htaccess

 

I have this but i don't think it's correct as i am just new on this..

 

<IfModule mod_rewrite.c>

Options +FollowSymLinks

Options +Indexes

RewriteEngine On

RewriteBase /

RewriteCond %{HTTP_HOST} !www.domain.com$ [NC]

RewriteCond %{HTTP_HOST} ^([a-z0-9-]+).domain.com [NC]

RewriteRule (.*) page1.php?user=%1 [L]

RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-]+).domain.com [NC]

RewriteRule (.*) page1.php?user=%2 [L]

</IfModule>

Link to comment
Share on other sites

http://www.mydomain.com/page1.php?user=$subdomain

 

This happens only in case if you have another wildcard redirection rule in .htaccess or some kind of url shortner redirection rule.

 

Remove that first

 

for subdomain.domain.com i.e if you dont want page1.php in url you need to set wildcard subdomain to directory as i stated above method1.

 

 

Link to comment
Share on other sites

<IfModule mod_rewrite.c>

Options +FollowSymLinks

Options +Indexes

RewriteEngine On

RewriteBase /

RewriteCond %{HTTP_HOST} !www.domain.com$ [NC]

RewriteCond %{HTTP_HOST} ^([a-z0-9-]+).domain.com [NC]

RewriteRule (.*) page1.php?user=%1 [L]

</IfModule>

 

i have modified some script n it works but image that is stored inside my folder didn't appear

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.