tlcable7
asked on
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
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]
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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]
ASKER
Works great! Thank you very much.
ASKER
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.
Open in new window