简体   繁体   English

htaccess正则表达式不接受某些特殊字符

[英]htaccess regex not accepting some special characters

I have a PHP script located at http://localhost/dir1/dir2/shift.php that I am passing urls as parameters to like so: http://localhost/dir1/dir2/https://google.com but I am getting a Forbidden you don't have access error. 我有一个位于http://localhost/dir1/dir2/shift.php的PHP脚本,该脚本将URL作为参数传递给我: http://localhost/dir1/dir2/https://google.com但我正在被禁止,您没有访问错误。 When I remove the : it works fine though. 当我删除:它工作正常。 I have checked my regex with some online regex validation tools and it says that it should be working but it doesn't 我已经使用一些在线正则表达式验证工具检查了我的正则表达式,它说它应该可以工作,但是不能正常工作

RewriteEngine on
RewriteRule ^dir1\/dir2\/([A-Za-z0-9\!\@\#\$\%\^\&\*\(\)\_\-\+\=\{\}\[\]\;\:\'\"\<\,\>\.\?\|\~\`\s\/\\]+)\/?  dir1\/dir2\/shift.php?url=$1 [L]

Any help would be great. 任何帮助都会很棒。 Thanks! 谢谢!

You should not use reserved characters in URL. 不应在URL中使用保留字符。

Though you can URL encode and then pass it as a parameter. 虽然您可以URL编码,然后将其作为参数传递。 For example: 例如:

http://localhost/dir1/dir2/shift.php?
param=http%3A%2F%2Flocalhost%2Fdir1%2Fdir2%2Fhttps%3A%2F%2Fgoogle.com

And then in shift.php you can first URL decode the parameter and then use. 然后在shift.php您可以先对参数进行URL解码,然后再使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM