How to Redirect HTTP to HTTPS with Exceptions

We have a requirement to redirect HTTP to HTTPS but we want to exclude image files from the redirection.
First of all, make sure mod_rewrite is enabled in Apache; in other words, make sure that /etc/httpd/conf/httpd.conf contains the line:

LoadModule rewrite_module modules/

Backup httpd.conf before you add the following:

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !^(.+)\.png$
RewriteCond %{REQUEST_FILENAME} !^(.+)\.jpg$
RewriteCond %{REQUEST_FILENAME} !^(.+)\.gif$
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [L,R]



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s