I have looked for the solution everywhere but couldn't find the exact solution I am looking for. I am not good at htaccess stuff. Need some help.
I have enforced "www" in my htaccess file and its getting on the way when I tried to create a subdomain.
I am using this setting i found and so far its working fine without subdomain.
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{HTTP_Host} ^(www\.)?example\.net$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
After creating a subdomain, its addding "www" at front and getting redirected to main site instead of subdomain.
For example: folder.domain.com -> becomes -> www.folder.domain.com (displayes the main site)
What modification is needed on top of what I have in this htaccess?
By the way my main site is in codeigniter and I also have this:
RewriteCond $1 !^(index\.php|js|media|style)
RewriteRule ^(.*)$ /index.php/$1 [L]
Wanted to install blog on subfolder and use it as subdomain.
easy way was to modify (add "blog")
RewriteCond $1 !^(index\.php|js|media|style|blog)
RewriteRule ^(.*)$ /index.php/$1 [L]
then I an access it as www.domain.com/blog
But I wanted it neat and clean way so that controller created URL will not conflict with sub-folders. Probably not allow access subfolders directly.
Thanks
Have your rules like this:
RewriteCond %{HTTP_HOST} ^mainsite\.com$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{HTTP_Host} ^(.+?)\.net$ [NC]
RewriteRule ^(.*)$ http://%1.com/$1 [L,R=301]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With