相对URL不能识别%2F
最近在一个项目中发现%2F的相对URL识别了,产生了404错误。
URL:http://w3schools.com/xxx%2Fxxx%2Ftest.asp?name=stale&car=saab
产生这个现象的原因是因为apache没有识别到encode后的URL。
可以在配置文件里面追加AllowEncodedSlashes On来解决。
<VirtualHost *:80>
DocumentRoot "/var/www/weble.org/app/webroot"
ServerName weble.org
AllowEncodedSlashes On
<Directory "/var/www/weble.org/app/webroot">
order deny,allow
allow from All
</Directory>
</VirtualHost>
还有一种解决办法就是在问题的画面,调用JS的decodeURIComponent方法。
Encode and decode a URI:
<script type="text/javascript">var uri="http://w3schools.com/my test.asp?name=ståle&car=saab";
var uri_encode=encodeURIComponent(uri);
document.write(uri_encode);
document.write("<br />");
document.write(decodeURIComponent(uri_encode));
</script>
The output of the code above will be:
http%3A%2F%2Fw3schools.com%2Fmy%20test.asp%3Fname%3Dst%C3%A5le%26car%3Dsaabhttp://w3schools.com/my test.asp?name=stale&car=saab
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。
- 上一篇: Java实现对JavaScript脚本文件的读取和执行
- 下一篇: 查询数据库锁和程序未释放的连接