Reputation: 45
Hey everyone I search around for this answer but could only find ways to redirect each URL individually.
My old site urls were like this:
www.domain.com/show_detail.php?item=item_description_of_various_lengths
new URLs are like this:
www.domain.com/shop/brands/titan/item_description_of_various_lengths/
Now I know how to redirect these on a 1 by 1 basis. I used the following code:
RewriteCond %{QUERY_STRING} ^item=item_description_of_various_lengths$ [NC]
RewriteRule show_detail.php http://www.domain.com/product-category/paint-spraying/hvlp-fine-finish/item_description_of_various_lengths/? [R=301,L]
Which works great and all but after writing about 200 of these I'm just wondering if there is a way to redirect ALL pages starting with show_detail.php to my home page and call it a day. Or even better 1 rule that will just redirect all of them to a search page which searches the "item_description_of_various_Lengths" phrase automatically.
Upvotes: 1
Views: 55
Reputation: 41219
You can use a regex catpure group to get value of the Item dynmically
RewriteCond %{QUERY_STRING} ^item=([^&]+)$ [NC]
And then replace description_of_v_length with %1? in the target url.
Upvotes: 1