1

I recently changed from an ASP site to a PHP site and I need to rewrite the old URL style to a new style. For example:

www.mydomain.com/store/list_view.asp?itemid=1000645

To this:

www.mydomain.com/store/list_view.php?id=1000645

so far I can get an ASP request to redirect to a PHP page using this:

RewriteEngine on
RewriteRule ^(.*)\.asp$ /$1.php [R=301,NC] 

I'd appreciate any help that you can provide and if possible an explanation of how it works, I'm new to working with redirects and .htaccess.

1 Answer 1

2

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{QUERY_STRING} ^itemid=(.+)$ [NC]
RewriteRule ^(.+?)\.asp$ $1.php?id=%1 [R=301,L,NC]

It matches QUERY_STRING for itemid parameter and captures it's value in %1 via RewriteCond. Then it replaces .asp by .php and adds id=%1 to complete the target URL.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.