Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Htaccess query string to another

Tags:

.htaccess

I have a url like:

shop/products.html?search_limiter=full&keyword1=apple

I want to rewrite this url to :

index.php?route=product/search&search=apple&description=true

using apache .htaccess

I try :

Redirect 301 /shop/products.html?search_limiter=full&keyword1=apple     http://www.example.com/index.php?route=product/search&search=apple&description=true

but it did not work.

Is there any way ?

like image 369
Ussosan Avatar asked Apr 29 '26 04:04

Ussosan


1 Answers

To rewrite on a querystring you have to use RewriteCond to match on the querystring first - you can then use that in the RewriteRule with a %N type match.

This will perform the rewrite you want (with any search term, not just "apple"):

RewriteEngine On
RewriteCond %{REQUEST_URI} shop/products.html
RewriteCond %{QUERY_STRING} search_limiter=full&keyword1=(\w+)
RewriteRule ^.*$ /index.php?route=product/search&search=%1&description=true [NC,L,R=301]

If you don't want to actually change the URL in the address bar, just the resource that's being loaded, leave R=301 (http 301 redirect) out of the flags.

like image 194
CD001 Avatar answered May 01 '26 14:05

CD001