Forum Moderators: phranque
AddType text/html .asp
AddHandler server-parsed .asp
DirectoryIndex default.asp
I have a few files that I moved to new directories that I fixed by adding the lines below next:
redirect 301 /olddirectory/oldpagename.asp [sitename.com...]
redirect 301 /olddirectory/oldpagename2.asp [sitename.com...]
redirect 301 /olddirectory/oldpagename3.asp [sitename.com...]
Then I tried to resolve any possible issues with PR splitting by directing to www.example.com/ in every possible case I could find an example for (including index.html and default.asp that I have incoming links pointing to). I used code that I found posted in various other threads in this forum:
Options Indexes FollowSymLinks Includes
RewriteEngine on
# Externally redirect requests for index.html in any directory to "/" in that directory
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.html\ HTTP/
RewriteRule ^(([^/]+/)*)index\.html$ http://www.example.com/$1 [R=301,L]
#
# Externally redirect requests for default.asp in any directory to "/" in that directory
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*default\.asp\ HTTP/
RewriteRule ^(([^/]+/)*)default\.asp$ http://www.example.com/$1 [R=301,L]
#
# Externally redirect requests for *all* non-canonical hostnames to canonical hostname,
# including case errors and appended FQDN indicator and/or port numbers.
RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
So my question is have I done anything wrong/bad? Every line of the file is in the order that I posted it in (with out my comments along the way)... This all appears to be working correctly but this is my first .htaccess file and I would really appreaciate any feedback for improvement. Thanks!
[edited by: RedWine at 10:27 pm (utc) on July 4, 2009]
Also, I'd suggest a tweak to the third rule, in order to prevent a self-inflicted DOS should your site be accessible via HTTP/1.0. Change the RewriteCond pattern to:
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
Jim
[edited by: jdMorgan at 4:30 pm (utc) on July 5, 2009]