web master
web master

Reputation: 245

Removing part of a URL with .htaccess

I'm trying to remove part of a URL with my .htaccess file. I have some previous rewrites that are working.

The url is https://example.com/index.php?route=product/product&product_id=5062&manufacturer_id=57

I have the index.php? removed with this rule, and it's working

RewriteEngine On
RewriteBase "/"
RewriteCond %{REQUEST_URI} ^/index\.php$
RewriteCond %{QUERY_STRING} (route.*)
RewriteRule "(.*)index.php" $1%1? [R=301,L]

Now there are some urls that have manufacturer_id=1-4 numbers, and I'm trying to remove those. I'm getting an internal redirect now.

The rule is

RewriteCond %{QUERY_STRING} (&manufacturer_id=[0-9]{1,4})

How can I remove it without it tripping over my other rules?

Thanks

Upvotes: 0

Views: 48

Answers (1)

anubhava
anubhava

Reputation: 786091

Place this rule at top of your .htacces to remove query parameter:

RewriteCond %{THE_REQUEST} \?(.*&)?manufacturer_id=[^&]*&?(\S*)\s [NC]
RewriteRule ^ %{REQUEST_URI}?%1%2 [R=301,NE,L]

Upvotes: 1

Related Questions