Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am using the the following script to redirect all requests send to http to https

RewriteEngine On

RewriteCond %{HTTPS} off

RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

I need to add an exception to this rule (for a specific page) for the reason that it's loading a js that it's on a server that does not have https. In FF, Chrome, it works. In IE it displays a nasty warning.

Any ideas on how to add a rule to my existing mod_rewrite code?

share|improve this question

2 Answers 2

You can add a second RewriteCond with a negated test (prefix the pattern with !). It will be ANDed with your existing RewriteCond.

Edit:

Example:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI}  !^/pageregex
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

Where pageregex is some regular expression describing the page that you want to make an exception for. Note that the regular expression could simply be a fixed string that uniquely identifies the specific page.

share|improve this answer
    
I didn't quite get it. Could you please be more explicit? –  Valentin Dec 20 '10 at 16:54
    
@Valentin: See my edited answer. –  Dennis Williamson Dec 20 '10 at 17:34

If you have mod_proxy installed and configured correctly, you can also serve that .js file over https.

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI}  !^/pageregex
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}    [C]
RewriteRule ^/home/to/js/file.js   http://example.com/home/to/js/file.js  [P]

The [C] flag allows the following rule to be executed as if it were part of the first rewrite rule. The [P] flag tells mod_rewrite to use mod_proxy to fetch the specified .js file and serve that transparently. This will probably make IE stop barking about "secure and insecure content on the same page, do you want to continue?" as the .js file would be served securely.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.