1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

.htaccess redirect for subdomains

Discussion in 'Search Engine Optimization (SEO)' started by sinasylum, Jan 10, 2007.

  1. sinasylum

    sinasylum New Member

    Joined:
    Jan 9, 2007
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    I am trying to make my site do this...

    when cpanel creates a sub-domain it just puts the root folder of the sub-domain as a sub-folder of the primary domain on the account. so http://sub.domain.com would also be http://www.domain.com/sub/.

    but I want to make it where two things happen... if someone accesses a sub-domain with www, it rewrites the subdomain url without www, and also when someone accesses my subdomain as a sub-folder of the root domain, it also rewrites that and directs the user to the subdomain url.

    Anyone know how to do both or either? thanks for all feedback!

    regards,

    the G4E newbie
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,283
    Likes Received:
    364
    Trophy Points:
    83
    Use the following
    Code:
    Options +FollowSymlinks
    RewriteEngine On
    RewriteCond %{HTTP_HOST}//s%{HTTPS} ^www\.(.*)//((s)on|s.*)$ [NC]
    RewriteRule ^ http%3://%1%{REQUEST_URI} [L,R=301]
    
    Use a hardcoded one for the domain and for the files have a wildcard.
     
  3. sinasylum

    sinasylum New Member

    Joined:
    Jan 9, 2007
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    thank you. i will give it a shot and see how things go.
     
  4. csgraduate

    csgraduate New Member

    Joined:
    Aug 11, 2007
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Hi,
    I am trying to redirect
    subdomain.mysite.com to mysite.com/index.php?id=subdomain passively
    so as the address in browser remains as subdomain.mysite.com .

    Below is the code from my .htaccess file.

    RewriteCond %{HTTP_HOST} !^www\.mysite\.com
    RewriteCond %{HTTP_HOST} ([^.]+)\.mysite\.com
    RewriteCond %{REQUEST_URI} !^/index\.php$
    RewriteCond %{QUERY_STRING} !^id=.
    RewriteRule (.*) /index.php?id=%1 [L]


    I don't know why it's still not redirecting as wanted.

    Any Ideas ?

    Thanks
     
  5. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,283
    Likes Received:
    364
    Trophy Points:
    83
    For Redirect the address bar will not remain as it is. It will change in the address bar.
     
  6. csgraduate

    csgraduate New Member

    Joined:
    Aug 11, 2007
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Yes , but its not even redirecting.
     

Share This Page