Forum Topic: Redirect Everything Except…

Forum: .htaccess Forum : Redirecting • Posted by Yael Miller • Updated:

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 appears broken. It’s the classic non-SSL elements on a SSL page problem.

I figure I have a few options:

  1. Ignore the problem. After all, who’s going to do to go to
  2. 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.
  3. Redirect stuff

Is it possible to redirect all pages of the website from https to http EXCEPT for the mail server pages? Which is

4 Replies to “Redirect Everything Except…”

Posted by Jeff Starr

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 “”. 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]

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.

Posted by Yael Miller •

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}*$
RewriteRule ^(.*)$$1 [R=301,L]
Posted by Jeff Starr

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, 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: it means the same thing.

Posted by Yael Miller •

I’m going to use your method. Thank you.