Exclude files from ssl redirect

I am using apache2 on ubuntu server. I have configured all traffic to redirect to ssl. I need to exclude two file from that ssl redirect.
/piwik.js
/piwik.php - this one will likely have query string args as well

Here are the contents of my conf-available/ssl-only.conf file…

RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule .* https://%{HTTP_HOST}/%{REQUEST_URI} [R=301,L,QSA]

What do I need to change here to exclude these two file from being redirected to ssl?
Thanks,
Rob A

Hi @riznob,

You can see the complete mod_rewrite documentation at https://httpd.apache.org/docs/current/mod/mod_rewrite.html (it’s quite extensive and describes lots of options for making extremely customized rewrite behaviors – you can get very specific).

When I searched for

I found several answers at StackOverflow that address your question, such as

If you look at the results from the Google search you should see other discussions about this kind of situation at StackOverflow and on other sites. Hopefully some of them will be helpful to you!

The simplest approach (though probably not the only possibility) seems to be to make a RewriteCond that defines conditions under which a rewrite will or will not happen; those could then relate to the exceptions that you want to apply. The StackOverflow answers give a few specific examples of how to do this.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.