How do handle URL redirects via .htaccess with multiple different scenarios.

I have created a .htaccess file at the following location:

I need calls to the pages: category.asp, parentCategory.asp, and product_detail.asp to be redirected to the same file name with .php as extension instead. All other requests should be sent to

Q1: As my code is now, the first three rules seem to be ignored, and the fourth one always executes. How can I make the first three take precedence?

Q2: When the fourth rewrite happens, it appends the query string to the redirect. How can I remove that?
Example link:
Results in:

Thank you,

Travis Cable
RewriteEngine on
RewriteRule ^category.asp /shop/category.php [NC]
RewriteRule ^parentCategory.asp /shop/parentCategory.php [NC]
RewriteRule ^product_detail.asp /shop/product_detail.php [NC]
RewriteRule ^(.*)$ [L,R=301]

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

- set L-Flags
- exclude your PHP files from your last rule

> it appends the query string to the redirect. How can I remove that?

Add a question mark:
RewriteEngine on
RewriteRule ^(category|parentCategory|product_detail)\.asp$ /shop/$1.php [NC,L]
RewriteCond $1 !^((parent)?category|product_detail)\.php$ [NC]
RewriteRule ^(.*)$ [L,R=301]

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tlcable7Author Commented:

Could you also help me get one more working. I have a search in the query string that I need redirected as well.

Example URL:

End result:

I have attache my code so far, which does not work.

RewriteRule ^search.asp\?SEARCH=([^&]*)$&?.*$1 [NC,L]

Open in new window

The queryString is not available in a rule-pattern, you've to use a condition:
RewriteCond %{QUERY_STRING} SEARCH=([^&]+)
RewriteRule ^search\.asp$ [R=301,NC,L]

Open in new window

tlcable7Author Commented:
Works great! Thank you very much.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Apache Web Server

From novice to tech pro — start learning today.