Adding encoded chars to the url breaks htaccess

偶尔善良 提交于 2020-01-04 01:19:21

问题


Here's my code:

RewriteEngine on
RewriteRule page/(.*) index.php?url=$1 [NC]

When I access page/http://google.com/ = works just fine
When I access page/http%3A%2F%2Fgoogle.com%2F = server reports 404

Martti Laine


回答1:


Apache returns a (somewhat non-intuitive) 404 in cases when you have encoded slashes in the request, but do not have AllowEncodedSlashes set to on. To confirm this is the case, check your error log, which likely contains an entry like this:

found %2f (encoded '/') in URI (decoded='/page/http://google.com/'), returning 404




回答2:


I believe you need the B (escape) flag:

RewriteRule page/(.*) index.php?url=$1 [NC,B]

That will escape the back-reference ($1) before adding it to the replace string.



来源:https://stackoverflow.com/questions/3388210/adding-encoded-chars-to-the-url-breaks-htaccess

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