linux:apache2_redirection
Apache2 https redirection
Force HTTPS from global conf
This section describes howto enforce a url redirection from regularly http to https, thus enforcing secure transport layer. The example below is used to ensure that phpmyadmin always uses https so passwords are not sent unencrypted. To do so, log in as root on server and ensure the rewrite and mod ssl modules in apache2 are installed, eg. use apt-get. To enable them if not enabled.
$ a2enmod mod_rewrite $ a2enmod mod_ssl
Next create a the following file in /etc/apache2/conf/rewrite.conf
<IfModule mod_rewrite.c>
<IfModule mod_ssl.c>
<Location /phpmyadmin>
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://hydrogen.notfound.dk/phpmyadmin [R]
</Location>
</IfModule>
</IfModule>
Next restart apache2 and you're done.
$ /etc/init.d/apache2 restart
Force https using .htaccess
To enforce http-ssl when entering a admin page the following mod rewrite can be used in .httaccess files.
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} admin/
RewriteRule ^(.*)$ https://notfound.dk/$1 [R,L]