I'm moving a website I work for from a Windows platform to Linux so all the pages ending in .asp will be renamed to .php Is there something I can put in the .htaccess file that means when Google comes to a page ending in .asp, it will then automatically know to look for the same file but ending in .php? The site has 100s of pages hence why I'm looking for such a method. Thanks.
Normally, I think you would use Mod_Rewrite; provided that all your page names have just plaintext in them, no - _ and similar, then this rule will most likely work for you That should catch any pages in upper or lower case with .asp on the end I did write about this on my blog, I'm fine-tuning it now, but if you're interested, have a peek here: Mod_Rewrite, The Basics -G
Thanks a lot! But shouldn't it be a 301? Because Google would actually need to be forwarded to the page with .php at the end as the .asp would no longer exist? It's not just plain text, it will also have PHP includes etc.
Had a quick read-around, and it looks like adding this tag to the end of the line does it; [R=301,L] Also, I made a little mistake on my rule, here it is revised. That should work, I'll add that to my post on Mod_Rewrite soon
gpearce, I've placed the htaccess in the root and it works for the root files but when you type /test/test.asp it won't redirect to .php probably because it's within a directory.. http://www.murraysworld.com/home.asp (works) http://www.murraysworld.com/test/test.asp (redirect fails) Can you help?
This version fixes the directory problem... RewriteEngine On RewriteRule ^(.*)\.asp$ /$1.php [R=301,L,NC]
Ah, nice one. Sorry for not coming back to help earlier, although ti looks like you fixed it I didn't get my normal email alert lol.
Don't forget the query_strings! RewriteEngine On RewriteBase / RewriteRule ^(.*)\.asp$ /$1.php [R=301,QSA,L,NC] Code (markup):
By adding the QSA you ensure that this.asp?anything gets rewritten to this.php?anything Otherwise this.asp?anything would be rewritten to this.php
You could also add asp as a handler for php applications. Might be easier and also screw up hackers thinking you run asp.