Simon Birch
Simon Birch

Reputation: 11

Dynamic URL rewriting via htaccess

My URLs need to be dynamically changed from:

https://www.example.com/webshop/recipe/Actimel-Breakfast-Lollies/145794?recipeId=145794&site=desktop
https://www.example.com/webshop/recipe/Actimel-Breakfast-Lollies/145794?selectedCategories=1087
https://www.example.com/webshop/recipe/Actimel-Breakfast-Lollies/145794?selectedCategories=1088
https://www.example.com/webshop/recipe/Actimel-Breakfast-Lollies/145794?selectedCategories=1090
https://www.example.com/webshop/recipe/Actimel-Breakfast-Lollies/145794?selectedCategories=2262
https://www.example.com/webshop/recipe/Actimel-Breakfast-Lollies/145794?selectedCategories=31246
https://www.example.com/webshop/recipe/Actimel-Breakfast-Lollies/145794?selectedCategories=40778

to:

https://www.example.com/webshop/recipe/actimel-breakfast-lollies/145794

Its a bespoke website, so it there anyway in .htaccess to remove anything after the ?selected and so on please?

Upvotes: 1

Views: 44

Answers (1)

MrWhite
MrWhite

Reputation: 45829

Basically, I just want the naked URL without the query, so it's removed.

In that case you would need an external redirect to remove the query string and lowercase the URL.

The following would redirect the stated URLs in your example. This would need to go near the top of your root .htaccess file:

RewriteEngine On

RewriteCond %{QUERY_STRING} .
RewriteRule ^webshop/recipe/Actimel-Breakfast-Lollies/145794$ /webshop/recipe/actimel-breakfast-lollies/145794 [QSD,R=302,L]

The QSD flag discards the original query string from the request.

This assumes you are already internally linking to the canonical URL without a query string (ie. /webshop/recipe/actimel-breakfast-lollies/145794).

(But this is not "dynamic URL rewriting" as stated in your question title.)

Upvotes: 1

Related Questions