saba
saba

Reputation: 29

use a true regex for a special url not working in htaccess

I have this url:

https://www.example.com/product/abcde595-556/?customize_changeset_uuid=b7fa6e4c-aa67-49c3-a08a-893c57d81b18&customize_autosaved=on

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

Answers (1)

boppy
boppy

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

Related Questions