url 重写中的 .htaccess 文件夹和文件名冲突

发布于 2024-09-24 18:21:33 字数 318 浏览 0 评论 0原文

我有以下 htaccess 允许 url 中没有文件扩展名:

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php

我的问题是我有一个名为 images.php 的文件和一个名为 images 的文件夹,所以当我使用 url: .com/images - 它需要我图像文件夹,其中:.com/contact - 带我到正确的页面。

I have the following htaccess to allow for no file extensions in the url:

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php

My problem is that i have both a file called images.php and a folder called images, so when i use the url: .com/images - it takes me to the images folder, where as: .com/contact - takes me to the correct page.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

草莓味的萝莉 2024-10-01 18:21:33

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

通过这两行,您可以说如果测试字符串(在您的情况下为“images”)不是目录也不是文件,请将其重写为 images.php 。现在,由于您有 images 目录,因此不满足第二条规则,并且 images 被重写到 images.php 内部。

更改文件夹的名称、更改脚本的名称或更改 .htaccess 规则和条件。

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

With these 2 lines, you say if the test string (in your case 'images') is not a directory and is not a file, rewrite it to images.php. Now, since you have images directory, the second rule is not satisfied and images is rewriten to images.php internaly.

Either change the name of the folder, change the name of the script, or change the .htaccess rules and conditions.

梦年海沫深 2024-10-01 18:21:33

我想如果你在你的规则之前添加这条规则应该有效......(但我没有测试它)

RewriteRule ^images/(.*)$    images/$1.php [L]

I think if you add before your rule this rule suppose to work ...(but I didn't test it)

RewriteRule ^images/(.*)$    images/$1.php [L]
赠我空喜 2024-10-01 18:21:33

正如 Tim Stone 建议的那样,删除 RewriteCond %{REQUEST_FILENAME} !-d 行将解决问题。

您的规则应如下所示:

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ $1.php

As Tim Stone suggested, removing the RewriteCond %{REQUEST_FILENAME} !-d line will fix the problem.

Your rules should then look as follows:

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