简体   繁体   English

适用于复杂站点地图+索引xml文件的Apache mod_rewrite规则

[英]Apache mod_rewrite rule for complex sitemap + index xml files

We manage sitemap (sitemap.org) files that have in the range of 500k links, which are changing often enough that we want to dynamically generate them, don't worry, we'll cache the results for a period but it's the mod_rewrite rules I'm having a problem with. 我们管理的站点地图(sitemap.org)文件的链接范围为50万个,这些文件的更改频率经常变化,因此我们希望动态生成它们,不用担心,我们会将结果缓存一段时间,但这是mod_rewrite规则我有问题。

Being as we have more than 50k links we need to be using sitemap index files. 由于我们有5万多个链接,因此我们需要使用站点地图索引文件。 Both the sitemaps and the index files will be redirected to a sitemap.php file which will use the filename pattern ( $_SERVER['REQUEST_URI'] ) to figure out which list to present. 站点地图和索引文件都将重定向到sitemap.php文件,该文件将使用文件名模式( $_SERVER['REQUEST_URI'] )找出要显示的列表。

The filename patterns would be as follows: 文件名模式如下:

www.domain.com/sitemap.index.xml
www.domain.com/sitemap.some_theme.xml
www.domain.com/sitemap.different_theme.xml

The mod_rewrite covers off our web application as well so I'll include all of it just in case something else may be overriding or conflicting with what I'm trying to accomplish: mod_rewrite也涵盖了我们的Web应用程序,因此,在其他情况可能会覆盖或与我要完成的工作冲突的情况下,我将包括所有内容:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^sitemap\.(.*)\.xml$ sitemap.php/ [NC,L]
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php/ [NC,L]
errordocument 404 /

The line I've inserted for the sitemaps specifically is: 我专门为站点地图插入的行是:

RewriteRule ^sitemap\.(.*)\.xml$ sitemap.php/ [NC,L]

Otherwise everything else is your standard web application stuff. 否则,其他所有内容都是您的标准Web应用程序。

--- EDIT --- -编辑-

Ok, so after much head scratching, I found the problem. 好的,所以经过大量的头部抓挠后,我发现了问题所在。 First, I simplified the rule slightly since I didn't need to capture the pattern match, only a positive response, the new rule is: 首先,我略微简化了该规则,因为我不需要捕获模式匹配,只需要一个肯定的响应,新规则是:

RewriteRule ^sitemap.*\.xml$ sitemap.php [NC,L]

So the kicker was simply swapping the order of it and the one below: 因此,踢球者只是在交换它和下面一个的顺序:

RewriteRule ^.*$ - [NC,L]
RewriteRule ^sitemap.*\.xml$ sitemap.php [NC,L]

I'm going to leave the question open for now, because I'd like to know why this made a difference. 我现在暂时不提问题,因为我想知道为什么会有所作为。 Thanks. 谢谢。

This rule is redundant and should be removed: 此规则是多余的,应删除:

RewriteRule ^.*$ - [NC,L]

Modify your code to this: 修改您的代码为此:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

ErrorDocument 404 /

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^/?sitemap\. /sitemap.php [NC,L]
RewriteRule ^ /index.php [L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM