意外的 htaccess 行为(mod_rewrite 和 apache)

发布于 2024-09-05 04:10:02 字数 856 浏览 4 评论 0原文

是的,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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

冰之心 2024-09-12 04:10:02

关闭 DirectorySlash Apache 指令。这似乎导致了 301 重定向。

DirectorySlash Off
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]

Turn off the DirectorySlash Apache directive. This seems to be causing the 301 redirect.

DirectorySlash Off
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]
为你鎻心 2024-09-12 04:10:02

尝试一次:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$    index.php?url=$1 [L,QSA]

Try this once:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$    index.php?url=$1 [L,QSA]
暖风昔人 2024-09-12 04:10:02

我有类似的问题。我的解决方案是停止在“坏”路径(末尾没有斜杠的目录)上重写 URL:

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*[^/])$ $1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*?)/*$ index.php?route=$1 [L,QSA]

I had a similar problem. My solution is to stop rewriting URL on "bad" paths (directories without slash at the end):

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*[^/])$ $1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*?)/*$ index.php?route=$1 [L,QSA]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文