Md Dang
Md Dang

Reputation: 131

Redirect htaccess php

I want to redirect this page with htaccess

products_filter.php?f16%5B0%5D=bla+bla+bla&cPath=72&M_ID=12x

to

products_filter.php?f16%5B0%5D=bla+bla&cPath=72&M_ID=12x

i tried this (and many other ways)

RewriteCond %{QUERY_STRING} ^f16%5B0%5D=bla+bla+bla$
RewriteRule ^products_filter\.php$ http://www.example.com/products_filter.php?f16%5B0%5D=bla+bla&cPath=72&M_ID=12x [L,R=301] 

what am i doing wrong here?

Upvotes: 1

Views: 158

Answers (2)

anubhava
anubhava

Reputation: 784898

Problem is using $ (end of input) in this regex:

RewriteCond %{QUERY_STRING} ^f16%5B0%5D=bla+bla+bla$

Since your query string is: 16%5B0%5D=bla+bla+bla&cPath=72&M_ID=12x

Change that line to:

RewriteCond %{QUERY_STRING} ^f16%5B0%5D=bla+bla+bla(&|$)

Update:

Looking at your question I realize that you are using quite a few special characters that need to be escaped.

RewriteCond %{QUERY_STRING} ^(f16%5B0%5D)=bla\+bla\+bla(?:&(.*)|$) [NC]
RewriteRule ^(products_filter\.php)$ /$1?%1=bla+bla&%2 [L,R=301,NE] 

PS: It is important to use NE flag here. Otherwise %5B and %5D will be further encoded by Apache.

Upvotes: 1

Lucas Willems
Lucas Willems

Reputation: 7063

Try this code :

RewriteCond %{QUERY_STRING} ^f16%5B0%5D=bla+bla+bla
RewriteRule ^products_filter\.php$ http://www.example.com/products_filter.php?f16%5B0%5D=bla+bla&cPath=72&M_ID=12x [L,R=301] 

Upvotes: 0

Related Questions