Difference between "Redirect permanent" vs. mod_rewrite

Posted by Stefan Lasiewski on Server Fault See other posts from Server Fault or by Stefan Lasiewski
Published on 2012-09-05T23:42:17Z Indexed on 2012/09/06 3:39 UTC
Read the original article Hit count: 553

Filed under:
|
|

This is an Apache httpd 2.2 server.

We require that access to this webserver be encrypted by HTTPS.

When web clients visit my site at http://www.example.org/$foo (port 80), I want to redirect their request to the HTTPS encrypted website at https://www.example.org/$foo .

There seem to be two common ways to do this:

First method uses the 'Redirect' directive from mod_alias:

<VirtualHost *:80>
    Redirect permanent / https://www.example.org/
</VirtualHost>

Second method uses mod_rewrite:

<VirtualHost *:80>
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
</VirtualHost>

What is the difference between a "Redirect permanent" and the mod_rewrite stanza. Is one better then the other?

© Server Fault or respective owner

Related posts about apache2

Related posts about mod-rewrite