How to handle special characters in .htaccess rules?

余生长醉 提交于 2019-12-11 09:08:11

问题


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??


回答1:


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.



来源:https://stackoverflow.com/questions/1124618/how-to-handle-special-characters-in-htaccess-rules

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!