Welcome to WebmasterWorld Guest from 184.73.126.70

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

General www 301 redirect catch all

Moved to an Unix server and have a super .htaccess file start (I think).

   
10:19 pm on Jul 4, 2009 (gmt 0)

5+ Year Member



Ok, so I moved an existing 7 year old domain name from an IIS server written in ".asp" files to apache server (no .asp). I was only using .asp files for the SSI function (no script) so I believe I have easily fixed (and dont have to change any file names/extensions) as a result of the move by adding this to my .htaccess file, I also set default.asp as the default page for my domain in the third line:

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]

4:28 pm on Jul 5, 2009 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Looks OK to me. You could combine the first and second rules by using the "local OR" to accept either asp or html in the regex patterns if you wanted to.

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)?$

This prevents a continuous (looping) redirect if the client does not send a "Host" header with its requests.

Jim

[edited by: jdMorgan at 4:30 pm (utc) on July 5, 2009]

10:17 pm on Jul 5, 2009 (gmt 0)

5+ Year Member



Thank you very much for the suggestion. I have made the change!
 

Featured Threads

Hot Threads This Week

Hot Threads This Month