GET 变量显示在 .htaccess 上的 URL 中重写不以 / 结尾的 URL
如果原始请求不是以正斜杠 (/) 终止,我的重写会出现暴露 GET 变量的问题。
这是我的规则:
# All requests are routed to PHP
RewriteRule ^(.*)$ framework/index.php?framework=$1&%{QUERY_STRING} [L]
如果我访问:
一切效果很好。如果我访问:
我会被重定向到:
http://www.domain.com/folder/?framework=folder
给出了什么?
I'm having an issue with my rewrites exposing GET variables if the originating request isn't terminated with a forward slash (/).
Here's my rule:
# All requests are routed to PHP
RewriteRule ^(.*)$ framework/index.php?framework=$1&%{QUERY_STRING} [L]
If I visit:
everything works great. If I visit:
I get redirected to:
http://www.domain.com/folder/?framework=folder
What gives?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来您的网络根目录中存在
/folder
。由于您尚未向 Apache 发送以斜杠结尾的 URL,并且请求的资源是一个文件夹,因此DirectorySlash
指令强制重定向到更正的 URL。不幸的是,
mod_rewrite
在此重定向发生之前就已经满足了您的请求,虽然它不会更改用于生成重定向的 URI,但它对查询字符串所做的更改不会分开以mod_dir
知道不包含它们的方式。因此,当重定向发送回浏览器时,它包含由RewriteRule
生成的查询字符串。对此的一个潜在解决方案(除了关闭
DirectorySlash
之外,由于文档中列出的原因,不建议这样做)是执行mod_dir
的工作,作为你的规则集:It sounds like
/folder
exists in your web root. Since you haven't sent Apache a slash-terminated URL, and the requested resource is a folder, theDirectorySlash
directive forces a redirect to the corrected URL.Unfortunately,
mod_rewrite
has a go at your request before this redirect occurs, and while it doesn't change the URI that is used in generating the redirect, the changes that it makes to the query string are not separated in a way thatmod_dir
knows not to include them. Therefore, when the redirect is sent back to the browser, it includes the query string generated by yourRewriteRule
.A potential solution to this (other than turning off
DirectorySlash
, which is not recommended for the reasons listed in the documentation) is to performmod_dir
's work for it as part of your rule set: