Customizing secure pages with mod_rewrite
I've wanted to have certain parts of the site be more secure, served over SSL, and thus did some experimenting with some mod_rewrite rules. I'd like to get some feedback on my work, which, in testing has worked for me.
Goal:
- To have all the admin pages be SSL
- All user preferences (esp when changing password) to be SSL
- To be able to create pages with keyword names (this case secure) that automatically were redirected to SSL
- Not to break the already working login ssl process
- Redirect all but the above back to port 80
Please, comments and suggestions are encouraged.
Example:
(from provided .htaccess)
Copy to clipboard
RewriteEngine On RewriteBase /base RewriteCond %{SERVER_PORT} 80 RewriteCond %{REQUEST_URI} tiki-admin.*$ [OR] RewriteCond %{REQUEST_URI} tiki-login.*$ [OR] RewriteCond %{REQUEST_URI} tiki-user_preferences.*$ [OR] RewriteCond %{REQUEST_URI} secure.*$ [OR,NC] RewriteCond %{QUERY_STRING} .*secure.*$ [NC] RewriteRule ^.*$ https://mysite/base/$0 [L] RewriteCond %{SERVER_PORT} 443 RewriteCond %{REQUEST_URI} !tiki-admin.*$ RewriteCond %{REQUEST_URI} !tiki-login.*$ RewriteCond %{REQUEST_URI} !tiki-user_preferences.*$ RewriteCond %{REQUEST_URI} !secure.*$ [NC] RewriteCond %{QUERY_STRING} !.*secure.*$ [NC] RewriteRule ^.*$ http://mysite/base/$0 [L] ... rest of file