Web - Mod Rewrite Basics


2005-01-12
Make sure the AllowOverride allows the use of mod rewrite.

# httpd.conf
AllowOverride All

Then create a .htaccess file in the folder where you would like to use mod_rewrite.

# .htaccess
RewriteEngine on
RewriteRule wrongurl correcturl.html
RewriteRule google http://www.google.com:8080/ [P]
RewriteRule journal blog [R]

“RewriteRule wrongurl correcturl.html” will redirect wronngurl to correcturl.html keeping the wrongurl in the address bar.

“RewriteRule google http://www.google.com:8080/ [P]” will proxy to google. (You must have mod_proxy loaded for this to work).

“RewriteRule journal blog [R]” redirects journal to blog correcting to the url to blog.