Remove tag= using htaccess (including processing order)

I have the following in my htaccess file:

RewriteEngine On
RewriteBase /
# Remove the design part of the URL
RewriteRule ^design/(.*)$ /$1 [L,NC,R]
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} s/+product/search/?tag=([^s&]+) [NC]
RewriteRule ^ /%1/? [R=301,L,NE]
# internal forward from pretty URL to actual one
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ product/search/?tag=$1 [L,QSA]

The external redirect and forwards was provided to me in this question:

RewriteRule for query string to static URL

I have one more issue. When I use my tag based search button linking to, it rewrites the URL perfectly to (as an example). However, when I click on a product (on that search page), it takes me to this URL: I want to remove the /?tag=hoodies from the end without causing a redirect loop. I tried this (but it caused a loop):

RewriteCond %{QUERY_STRING} ^tag=(.*)$
RewriteRule ^(.*)$ /%1/ [R=301,L]

Any suggestions?

Source: .htaccess

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.