Forum Moderators: phranque
I have a secure subdomain of my site that is almost in exclusive use, ie. [subdomain.mysite.com...] (there is only one page in [mysite.com...] to redirect to subdomain)
What I would like, is for anyone who types:
mysite.com/subdomain/blahblah.....
or
www.mysite.com/subdomain/blahblah.....
or
[(either...] of the above)
or
basically ANYTHING that doesn't have the subdomain name at the start of the url,
to get automatically redirected to:
[subdomain.mysite.com...]
(AND if /subdomain/ is in the directory path to just ignore it)
One other problem at the moment (it is probably related) is that search engines are somehow finding and listing:
[subdomain.mysite.com...]
and
[subdomain.mysite.com...]
I have checked ALL links in ALL files to make sure that none of them have .../subdomain/... (although I almost exclusively use relative addressing)
Currently, my .htaccess in the root directory is:
# use utf-8
AddDefaultCharset utf-8
# disable all directory browsing
Options All -Indexes
IndexIgnore *
And my .htaccess in the subdomain directory is:
# force secure browsing
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^ [subdomain.mysite.com%{REQUEST_URI}...] [NS,R=301,L]
Please can anyone point me in the right direction?
Thanks & regards,
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^subdomain\.example\.com
RewriteRule ^(subdomain)?(.*)$ https://subdomain.example.com/$2 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /subdomain/
RewriteCond %{HTTP_HOST} ^subdomain\.example\.com [NC]
RewriteRule ^subdomain/(.*)$ https://subdomain.example.com/$1 [R=301,L]
If the subdomain-subdirectory is present in the URL-path requested from any domain exceopt the subdoamin, it will be discarded by the first rule before the redirect to the subdomain.
If the subdomain is present in the URL-path requested by the client from the subdomain, then it will be discarded by the second rule.
Jim
[edited by: jdMorgan at 6:47 pm (utc) on Nov. 23, 2007]
Can these be redirected, or am I being a bit too picky?
Regards,
check out some of the topics regard domain name canonicalization in the apache web server forum library [webmasterworld.com].
As you can probably tell by now, Apache & .htaccess are NOT my field of experience, which is why I came here, and why people with unusual fish health problems come to me - Go directly to the experts to have it explained in laymans terms and avoid disasters.
I appreciate that you do this out of the goodness of your hearts, and that I (we) should at least "have a go" before posting, and that is what I have done, but I have now gone way beyond my limited knowledge on this subject and was hoping that someone could help me out in this final little bit of my problem.
You see, I thought that my .htaccess in /subdomain/ that contains:
# force secure browsing
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^ [subdomain.mysite.com%{REQUEST_URI}...] [NS,R=301,L]
Forced ALL secure browsing TO [subdomain.mysite.com...] (but obviously not!)
Thanks again and Regards,
In line 4, should I be removing the 'L' as it isn't the last rule?
And, would lines 6&7 be better served with:
RewriteCond %{HTTP_HOST}!^subdomain\.example\.com$ [NC]
RewriteRule ^(.*)$ [subdomain.example.com...] [R=301,L]
(I think) saying that if I DON'T have "https://subdomain.example.com" then make it so (sorry a TNG fan as well)
Regards,
The [L] flag says, "If the patterns of this RewriteRule and its RewriteConds (if any) match, stop mod_rewrite processing here and apply the rule immediately."
Jim
Regards,
Next, why doesn't the code I use work as expected? I believe I have said:
If the URL is being entered as a secure connection - then make it [subdomain.example.com...]
So why, when you type [example.com...] does it refuse to honour that statement and serve a page as [example.com...] with a 'certificate error' and not change it to [subdomain.example.com?...]
Regards,
...why [...] does it refuse to honour that statement...?
Because SSL validation is processed before mod_rewrite and other Apache modules (for security reasons). So in order to avoid this cert error problem, you'll need two Certificates -- one for each domain. It is critical when using SSL to avoid links to the 'wrong' domain for this reason.
Jim