意外的 htaccess 行为(mod_rewrite 和 apache)
是的,mod_rewrite 让我发疯。
问题是:
的 htaccess
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]
当我尝试访问页面 advantix
(所以地址是 www.mywebsite.com/advantix
)时,我 被重定向到 advantix/?url=advantix
查看访问日志,中间有一个可疑的301
"GET /advantix HTTP/1.1" 301 335 "-" "Mozilla/5.0"
"GET /advantix/?url=advantix HTTP/1.1" 200 186 "-" "Mozilla/5.0"
有一个重要的细节:advantix 是一个目录。
因此,如果我评论该规则,advantix
就会转到该文件夹并列出文件。
如果有文件夹匹配,为什么它会自动应用 /
?
我不想访问该文件夹,我想访问 index.php?url=advantix
通过调用 advantix
。
我也有 rewriteLogs,但它们没有更多帮助。我的虚拟主机配置有 Directory
标记和 Options All
,如果有帮助,我对此不太了解。
Yeah, mod_rewrite is driving me crazy.
Here is the problem:
my htaccess
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]
when i try to access the page advantix
(so address was www.mywebsite.com/advantix
), i'm being redirected to advantix/?url=advantix
Looking at the access log, i have a suspicious 301 in the middle
"GET /advantix HTTP/1.1" 301 335 "-" "Mozilla/5.0"
"GET /advantix/?url=advantix HTTP/1.1" 200 186 "-" "Mozilla/5.0"
There is one important detail: advantix is a directory.
So, if i comment that rule, advantix
goes to the folder and list the files.
Why it applies automatically the /
if there's a folder matching?
I don't want to reach the folder, i want to reach index.php?url=advantix
with a call to advantix
.
I have the rewriteLogs too, but they didn't help more. My vhost conf has Directory
tag with Options All
, if helps, i don't know much about that.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
关闭 DirectorySlash Apache 指令。这似乎导致了 301 重定向。
Turn off the DirectorySlash Apache directive. This seems to be causing the 301 redirect.
尝试一次:
Try this once:
我有类似的问题。我的解决方案是停止在“坏”路径(末尾没有斜杠的目录)上重写 URL:
I had a similar problem. My solution is to stop rewriting URL on "bad" paths (directories without slash at the end):