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

I have created a .htaccess file at the following location:
http://specialopspaintball.com/shop/

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 http://shop.specialopspaintball.com/.

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: http://specialopspaintball.com/shop/imageviewer.asp?SKU=611+0002&IMAGE=b
Results in: http://shop.specialopspaintball.com/?SKU=611+0002&IMAGE=b

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 ^(.*)$ http://shop.specialopspaintball.com/ [L,R=301]

Open in new window

tlcable7Asked:
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.

caterham_wwwCommented:
- 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 ^(.*)$ http://shop.specialopspaintball.com/? [L,R=301]

Open in new window

0

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:
Perfect!

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:
www.specialopspaintball.com/shop/search.asp?SEARCH=221+0022&x=0&y=0

End result:
http://shop.specialopspaintball.com/catalogsearch/result/?q=221+0022

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


RewriteCond %{QUERY_STRING} SEARCH
RewriteRule ^search.asp\?SEARCH=([^&]*)$&?.* http://shop.specialopspaintball.com/catalogsearch/result/?q=$1 [NC,L]

Open in new window

0
caterham_wwwCommented:
The queryString is not available in a rule-pattern, you've to use a condition:
RewriteCond %{QUERY_STRING} SEARCH=([^&]+)
RewriteRule ^search\.asp$ http://shop.specialopspaintball.com/catalogsearch/result/?q=%1 [R=301,NC,L]

Open in new window

0
tlcable7Author Commented:
Works great! Thank you very much.
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.