Page 1 of 1

how to redirect on file type

Posted: Fri Dec 14, 2007 1:05 pm
by michlcamp
I'm migrating a site to a new server - the site is old and has a lot of .cfm and .asp files which are no longer useful but do still show up in search engines. The new server is Linux, and I don't want to install the site on a Windows server nor purchase a ColdFusion license....

I want to redirect any visits to those older files automatically to newer .php or .html files.

here's my question:

If a visitor clicks a search engine link pointing to one of the older files with the .cfm or .asp extension, is there a .php script way to redirect that visitor to the newer .php or .html files without having to place a redirect instruction on each of the files?

Any/all help much appreciated.
thanks.
michael

Posted: Fri Dec 14, 2007 1:13 pm
by John Cartwright
Have you looked into Mod Rewrite yet?

Off the top of my head you could try something like (untested)

Code: Select all

RewriteEngine On
RewriteRule ^(.*?).asp$ $1.php
RewriteRule ^(.*?).cfm$ $1.php
However, I would probably set the 404 handler to send the permanent redirect header and redirect to the appropriate url. This will update the search engine listings to the correct page as well :).