1

In my .htaccess file I have defined following rule,

RewriteRule t/([^.]+)/$ /videos/tag.php?tag=$1 [QSA]

The above rule works fine if I am browsing http://example.com/videos/t/world+news/ or http://example.com/videos/t/events/

but when I am browsing http://example.com/videos/t/business+%26+world/ (here original tag is: business & world) then in my query string tag variable I am getting only business. '& world' is not coming when I am fetching variable data through $_GET['tag']

Can anyone please tell where is the problem in the above rule??

djmzfKnm
  • 26,679
  • 70
  • 166
  • 227

2 Answers2

5

Try the B flag to escape the backreference:

RewriteRule ^t/([^.]+)/$ /videos/tag.php?tag=$1 [B,QSA]

Edit   How about this:

RewriteRule ^([^&]*)&(.*)/$ $1\%26$2 [N,NE]
RewriteRule ^t/([^.]+)/$ /videos/tag.php?tag=$1 [QSA]

The first rule is to replace the & with %26.

Gumbo
  • 643,351
  • 109
  • 780
  • 844
  • Its not working. When I am adding [B,QSA] then it gives me "500 Internal Server Error" without that B only [QSA] is working fine. ?? – djmzfKnm Jul 14 '09 at 10:52
  • I think that flag was introduced with Apache 2. – Gumbo Jul 14 '09 at 11:46
  • Ok,but I am running my website with this configuration `Apache/2.2.3 (CentOS)` and other thing is your new code is not working? don't know hwy but its displaying only a blank page after adding that %26 rule. – djmzfKnm Jul 14 '09 at 17:52
  • One more thing your new rule will only replace the `&` or it will work same like `B` flag what you suggested before. – djmzfKnm Jul 14 '09 at 17:53
  • The first rule should be applied as long as there are `&` in the URL path. So every `&` would be replaced by `%26`. – Gumbo Jul 17 '09 at 10:03
  • The `B` flag was introduced in 2.4.26 (see https://httpd.apache.org/docs/current/rewrite/flags.html). – Potherca May 31 '18 at 15:27
0

Finally i have a solution for you:

RewriteRule ^t/([^/.]+)/$ /videos/tag.php?tag=$1 [QSA,L]