Redirect old asp links on concerned sister sites to current php page

Hi everyone,

I am new to htaccess redirects and so need a little help.

I have a new site running on php and i have to redirect all links that point to asp to route to php page. Example… links to

http://www.mysite.com/tour.asp?id=1234

should go to

http://www.mysite.com/tour.php?tourid=1234

Let me mention here though its very obvious that 1234 is dynamic here and will change.

How can i accomplish this using htaccess? I am using the following server config
Apache/2.2.22 (Unix) mod_ssl/2.2.22 OpenSSL/1.0.0-fips mod_bwlimited/1.4 PHP/5.3.16

Thanks

lw,

Welcome to SitePoint!

If the value of id and tourid are identical, the answer is simple:

# in .htaccess in mysite.com's DocumentRoot

# capture the value of id (for tourid)
RewriteCond %{QUERY_STRING} ^id=([0-9]+)
# redirect .asp request to .php with tourid
RewriteRule ^([a-z]+)\\.asp$ $1.php?tourid=%1 [R=3-1,L]

While the comments should be sufficient explanation, you may need more. If you do, you might benefit from reading the mod_rewrite tutorial linked in my signature as it contains explanations and sample code. It’s helped may members (all but one) and should help you, too.

Regards,

DK