Redirecting pages to HTTPS with htaccess

  Print
Once you have installed your SSL certificate on your website you need to look at how you are going to ensure visitors use HTTPS on the correct pages.

The easiest method of doing this is via htaccess. If you are running on a Windows Server you can use ISAPI_Rewrite which adds support for htaccess to your server.

The htaccess will need to contain the following in all cases

RewriteEngine On
To simply redirect your entire website to HTTPS add the following to your htaccess

RewriteCond %{HTTPS}off RewriteRule (.*) <a><a>https://%{HTTP_HOST}%{REQUEST_URI</a></a>} [R=301,L]
If you only want to redirect certain folders or pages to HTTPS then use the following

RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} ^(list|of|folders|pages|use|pipes|for|multiples)/?.*$
RewriteRule (.*) <a><a>https://%{HTTP_HOST}%{REQUEST_URI</a></a>} [R=301,L]
To ensure pages you do not want as HTTPS are redirected to HTTP use the following

RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^(list|of|folders|pages|that|should|be|HTTPS)/?.*$
RewriteRule (.*) <a href=""><a href="">http://%{HTTP_HOST}%{REQUEST_URI</a></a>} [R=301,L]


Related Articles

Login