0

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?

1

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.

  • I didn't quite get it. Could you please be more explicit? – Valentin Dec 20 '10 at 16:54
  • @Valentin: See my edited answer. – Paused until further notice. Dec 20 '10 at 17:34
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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