how to redirect on file type

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
michlcamp
Forum Commoner
Posts: 78
Joined: Mon Jul 18, 2005 11:06 pm

how to redirect on file type

Post 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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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 :).
Post Reply