htaccess,缩短的 url 不应与文件匹配

发布于 2024-09-10 03:07:20 字数 728 浏览 4 评论 0原文

我的 apache2 和 .htaccess 规则有一点问题。

例如:
我有一个缩短的 uri,

www.domain.tld/sitemap  

必须由重写规则重写,在 php 文件中重定向以显示站点地图。 问题是,根文件夹中存在一个名为 sitemap.xml 的文件。 我的 apache 自动调用 sitemap.xml 文件,但我不希望这样。 该文件应该仅在 uri 时调用

www.domain.tld/sitemap.xml

是否有可能在调用缩短的 URI 时避免调用该文件?

这只是一个例子。有些文件需要位于根文件夹中,并且无法从根文件夹移动到子文件夹中(这将是解决此问题的最简单方法,但在我的情况下不可能)。要求这些文件可以通过 uri 调用。

有谁知道如何解决这个问题?

我当前的 .htaccess 文件

RewriteCond %{REQUEST_URI} ^(.*)$
RewriteCond %{REQUEST_FILENAME} !index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /index.php?urlseg=%1&%{QUERY_STRING} [NC,L]

非常感谢!

I have a little problem with my apache2 and .htaccess rules.

for example:
I have a shortened uri like

www.domain.tld/sitemap  

which has to be rewritten by a rewriterule, redirected in a php File to display the sitemap.
The problem is, that in the root folder a file named sitemap.xml exists.
My apache automatically calls the sitemap.xml file but i don`t want that.
The file should be only called when uri is

www.domain.tld/sitemap.xml

is there a possibility to avoid the call of this file when the shortened URI is called?

this is just an example. There are some files that are required to be in the root folder and can`t moved from there into a subfolder (which would be the easiest way to fix this problem, but its not possible in my situation). it is required that these files are callable by uri.

Has anyone an idea how to fix this problem?

my current .htaccess file

RewriteCond %{REQUEST_URI} ^(.*)$
RewriteCond %{REQUEST_FILENAME} !index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /index.php?urlseg=%1&%{QUERY_STRING} [NC,L]

Thanks a lot!

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

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

发布评论

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

评论(1

痴情换悲伤 2024-09-17 03:07:20

您可能已启用 MultiViews ,它会自动将不存在的资源 /sitemap 解析为现有资源 /sitemap.xml。特别是在您使用 mod_rewrite 的情况下,我确实认为不需要 MultiViews,因此您可以通过将其添加到 顶部来关闭它。 htaccess 文件:

Options -MultiViews

这样做有望防止这种情况发生。

You likely have MultiViews enabled, which auto-resolves your non-existent resource /sitemap to the existent resource /sitemap.xml. Especially in cases where you're using mod_rewrite, I really see no need for MultiViews, so you can turn it off by adding this to the top of your .htaccess file:

Options -MultiViews

Doing so should hopefully prevent this from happening.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文