Forum Topic: Redirect Everything Except…
I’m the web designer for a company’s website. In terms of importance to the company, the forward facing website is much less important than all the email addresses @companywebsite.
The sysadmin for the company setup a SSL certificate for email purposes. The website itself will NOT be selling anything or otherwise exchanging private data.
Sysadmin sent me an email saying that https://companywebsite.com
appears broken. It’s the classic non-SSL elements on a SSL page problem.
I figure I have a few options:
- Ignore the problem. After all, who’s going to do to go to
https://companywebsite.com
? - Fix the broken image problem which according to all the docs I can find will slow down a site because to fix the problem I must force everything to HTTPS.
- Redirect stuff
Is it possible to redirect all pages of the website from https to http EXCEPT for the mail server pages? Which is webmail.companywebsite.com
4 Replies to “Redirect Everything Except…”
The trick is the subdomain; for a typical setup, the .htaccess used for the subdomain “webmail” will be different than the .htaccess used for the primary domain “companywebsite.com”. If so, adding something like this to the root directory of the primary domain should work:
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_URI} !webmail\.companywebsite\.com [NC]
RewriteRule ^(.*)$ http://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
</IfModule>
The RewriteCond is a precaution and technically shouldn’t be needed because requests for anything on the subdomain will be handled by the subdomain’s .htaccess file.
I hope it is clear, let me know if I can elaborate on anything.
What does the code you shared above actually mean? The first line says for webmail don’t do something, correct? And is the second line telling it to redirect https to http?
The below is what I pieced to together from various internet sources and I think it works but I’m not sure if it works well.
<IfModule mod_rewrite.c>
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} webmail.website.com/?.*$
RewriteRule ^(.*)$ http://website.com/$1 [R=301,L]
</IfModule>
Yes, that’s correct regarding the previous method.
That one you post looks suitable, but as-is it’s only redirecting requests that DO match webmail.website.com, if that’s what you’re after.. if not, just prepend a “!” to redirect anything except the webmail stuff.
Also, the regex in the rewrite condition could be written simply as:
webmail.website.com
..as it means the same thing.
I’m going to use your method. Thank you.