Monday, January 24, 2011

Apache: Redirect http urls to https urls

To redirect http requests to https with Apache, you could do a normal redirect with:
Redirect permanent / https://your-url

However, this will redirect any request to https://your-url/. If someone requested http://your-url/this-uri they would be redirected to https://your-url/ without the uri segment.

To redirect them to https://your-url/requested-uri you would use mod_write instead:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://your-url/$1 [R,L]

No comments: