htaccess,缩短的 url 不应与文件匹配
我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能已启用
MultiViews
,它会自动将不存在的资源/sitemap
解析为现有资源/sitemap.xml
。特别是在您使用mod_rewrite
的情况下,我确实认为不需要MultiViews
,因此您可以通过将其添加到顶部来关闭它。 htaccess
文件:这样做有望防止这种情况发生。
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 usingmod_rewrite
, I really see no need forMultiViews
, so you can turn it off by adding this to the top of your.htaccess
file:Doing so should hopefully prevent this from happening.