Module mod_rewrite (Apache's URL Rewriting Engine) is such a dandy feature and not just for the oft touted "friendly URLs", which are admittedly cool, but it really shines as an alternative means of managing moved files, in lieu of a gazillion redirection files.
Sadly, when, in the low days of last Winter, I set out to reduce Pizza's 404's to as near to zero as possible I took what I thought was the smart and easy route. Checking the server logs for 404s I created appropriate redirection files for each missing HTML page. This works, and if you're unable to use rewrite by all means get rid of those 404's any way you're able, but using meta refresh tags accomplishes the task in a far too obvious way; the user sees your "we've moved" page, if only for a few seconds before the page refreshes and loads the new resource.
Mod rewrite masks all of this, and leaves an appropriate "forwarding address" for search engines.
Apache httpd.conf
The place to begin is in Apache's httpd.conf file, you need to locate the two places that will allow directory level controls for rules such as this. OK, is this the only way, well, no. But this is my story, of how I slowly did this, so this is a way that works.
-
<Directory />
-
Options FollowSymLinks
-
AllowOverride All
-
</Directory>
Be sure to find both occurrences of AllowOverride. I wasted an hour attempting to resolve why my mod rewrite in .htaccess wasn't working (you'll know if it isn't working when all you get are 404s) before noticing the second place where AllowOverride needed to be set.
AllowOverride All
.htaccess
OK, having told Apache to look for and execute .htaccess files for each directory you'll need to write 'em. The r=301 will include redirection message in the http header, making search engines happy. The nc is non-casesensitive.
-
<IfModule mod_rewrite.c>
-
RewriteEngine On
-
RewriteBase /
-
RewriteCond %{REQUEST_FILENAME} -f [OR]
-
RewriteCond %{REQUEST_FILENAME} -d
-
RewriteRule ^.*$ - [S=100]
-
-
RewriteRule ^bmanphotos\.htm$ /photos/burningman.htm [r=301,nc]
-
RewriteRule ^halloween02\.htm$ /photos/halloween02.htm [r=301,nc]
-
RewriteRule ^ksphotos\.htm$ /photos/kansas.htm [r=301,nc]
-
RewriteRule ^ludders\.htm$ /photos/ludders.htm [r=301,nc]
-
RewriteRule ^picture\.htm$ /photos/index.htm
