Re: Redirect http://yoursite.com to http://www.yoursite.com
Posted 16 years 10 months ago
As in you have a subdomain and its folder is in public_html? I wouldnt do a rule, I would just move it outside of the public_html and make you subdomain look there, then only subd.mydomain.com would work.
Re: Redirect http://yoursite.com to http://www.yoursite.com
Posted 16 years 10 months ago
I dont follow you. I created those subdomains with cpanel and they are physically in subfolders of /public_html/ so they are accessible either via subdomain.domain.com and
www.domain.com/subdomain/
and domain.com/subdomain/
I have found these rules that work NICE for me so far :
Options +FollowSymLinks
RewriteEngine on
# Remove "www." from any subdomain requests
# (Same rule will work for all subdomains)
RewriteCond %{HTTP_HOST} ^www\.([^.]+)\.mysite\.com [NC]
RewriteRule (.*) http://%1.mysite.com/$1 [R=301,L]
#
# Redirect client subdirectory requests to subdomain
# (Does not affect internal rewrites. One ruleset is required per subdomain)
RewriteCond %{HTTP_HOST} ^(www\.)?mysite\.com [NC]
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /subdomain1/
RewriteRule ^subdomain1/(.*)
subdomain1.mysite.com/$1
[R=301,L]
Re: Redirect http://yoursite.com to http://www.yoursite.com
Posted 16 years 10 months ago
yeah, but what I am saying is, in Cpanel (depending on the version), you can select where the roots of the subdomains are located. So instead of locating them in say public_html, you could put the roots in:
home/subdomains/subdomain1 or whatever - then they can only be accessed by subdomain1.mysite.com or w/e
See what I mean? Much better for managing your website to I would say!
I know this is an extremely old post, but if I invoke this script in .htaccess and enter
mydomain.com
in the address bar, should I then see this address get replaced with
www.mydomain.com
when I hit <ENTER>?