.htaccess redirect for subdomains

sinasylum's Avatar, Join Date: Jan 2007
Newbie Member
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
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Quote:
Originally Posted by sinasylum
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,
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]
Quote:
Originally Posted by sinasylum
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.
Use a hardcoded one for the domain and for the files have a wildcard.
0
sinasylum's Avatar, Join Date: Jan 2007
Newbie Member
thank you. i will give it a shot and see how things go.
0
csgraduate's Avatar
Newbie Member
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
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
For Redirect the address bar will not remain as it is. It will change in the address bar.
0
csgraduate's Avatar
Newbie Member
Yes , but its not even redirecting.