Reputation: 29
I have this url:
and I want redirect above url to :
https://www.example.com/product/abcde595-556/
I write this regex that worked in regex testing tools but not working in htaccess:
^(.*)\?
My htaccess code is this:
RewriteEngine On
RewriteRule ^(.*)\? $1 [R=301,L]
please help me and tell why not working that's regex
Upvotes: 0
Views: 37
Reputation: 1908
The query string is usually NOT part of the URL that the Rewrite Engine matches, so your RewriteRule tries to match something that is not there.
I think you are searching for the option QSD with redirects, that removes the query string:
# Turn ReriteEngine On
RewriteEngine On
# Only apply rewrite if query string is set
RewriteCond %{QUERY_STRING} .
# do the rewrite
RewriteRule ^(.*)$ $1 [R=301,QSD,L]
(htaccess is untested)
Upvotes: 3