“%”错误和访问
我遇到了一些包含 % simbol 的 URL 的 htaccess 问题。
例如: ......he-lost-10%-of-his-money.html
错误请求 您的浏览器发送了该服务器无法理解的请求。 此外,尝试使用 ErrorDocument 处理请求时遇到 404 Not Found 错误。
在我的 htaccess 中:
RewriteRule ^([^/]+).html$ abc.php?url=$1 [L]
我必须做什么?
I have a htaccess problem with some URLs that contains the % simbol.
For example: .......he-lost-10%-of-his-money.html
Bad Request
Your browser sent a request that this server could not understand.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
In my htaccess:
RewriteRule ^([^/]+).html$ abc.php?url=$1 [L]
What must I do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
根据您想要执行的操作,请参阅此处:
.htaccess mod rewriterule 和&符号(第一个答案,如果您传递 URL,则适用于 % 字符)
htaccess 从 URL 转义百分比 (%)
.htaccess mode_rewrite 匹配百分比符号问题
urlencoded 正斜杠正在破坏 URL
... https://stackoverflow.com/search?q=htaccess+percent
如果 url= 的内容不是原始/请求的脚本而是传递的变量,则您将要需要在原始 PHP 脚本中 rawurlencode 。
Depending on what you're trying to do, see here:
.htaccess mod rewriterule and ampersands (first answer, applicable for % character if you're passing the URL)
htaccess to escape percent (%) from URL
.htaccess mode_rewrite match percent symbol problem
urlencoded Forward slash is breaking URL
... https://stackoverflow.com/search?q=htaccess+percent
If the content of url= isnt the originating/requested script but a passed variable, you will need to rawurlencode it in the orginating PHP script.
% 在 URL 中具有特殊含义(而且非常重要),因此应该对其进行正确的 urlencoded。或者用“百分比”一词来更改它,这对于 SEO 目的来说甚至更好。
% has a special meaning in the URL (and very significant one) and thus it ought to be properly urlencoded. Or change it with word "percent" which is even better for SEO purposes.
对 URL 进行编码以便可以传递特殊字符(例如空格字符)时,它们会被转换为十六进制数字,并在前面添加
%
字符。您的 URL 包含序列%-o
,该序列无效并会导致 Apache 引发错误。尝试使用相同的 URL,但将%
替换为%25
并查看效果如何。When encoding a URL so special characters can be passed through (such as a space character), they are converted into hex digits, prepended with the
%
character. Your URL contains the sequence%-o
, which is not valid and causes Apache to throw the error. Try that same URL, but replace the%
with%25
and see how it goes.