Link to home
Start Free TrialLog in
Avatar of debugitbob
debugitbobFlag for United States of America

asked on

Htaccess url redirect change asp to php and pass url params

Here is what I want to do. goes to template.asp?TemplateID=## I want them to get redirected to template.php?aid=##

This is what I want to put into my htaccess file will the last 2 strings work?

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} ^TemplateID=([0-9])$
RewriteRule template\.asp template\.php\?aid=%1/? [R=301]
ASKER CERTIFIED SOLUTION
Avatar of virmaior
virmaior
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of debugitbob

ASKER

it doesn't seem to work. The site was migrated from ASP to PHP and it moved servers to a non IIS server. so all the old links from Google point to the old asp pages. I want to redirect to the PHP versions, I made a place holder asp page to redirect but because the server is non IIS it just shows the html code. so I put the redirect info into the .htaccess and the only line working there is a ErrorDocument 404 redirect I have.

Here is the full file

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} ^TemplateID=([0-9]*)$
RewriteRule template\.asp?TemplateID=([0-9]*) redirect\.php\?aid=%1/? [R=301]
ErrorDocument 404 http://www.dentalcomfortzone.com/inthenews.php
so what I want is when someone goes to dentalcomfortzone.com//template.asp?TemplateID=88 I want them to get redirected to dentalcomfortzone.com/template.php?aid=88
try this for the last line:
RewriteRule template\.asp\?TemplateID=([0-9]*) redirect.php?aid=%1 [R=301]

also check  your log to see if one of the lines is considered broken.

> .. will the last 2 strings work?
no

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} ^TemplateID=([0-9]*)$
RewriteRule template\.asp template.php?aid=%1 [R=301]

If you want to have the query string also, you need to add the QSA flag.
Keep in mind that this rule matches template.asp anywhere in the path.