繁体   English   中英

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

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

我们管理的站点地图(sitemap.org)文件的链接范围为50万个,这些文件的更改频率经常变化,因此我们希望动态生成它们,不用担心,我们会将结果缓存一段时间,但这是mod_rewrite规则我有问题。

由于我们有5万多个链接,因此我们需要使用站点地图索引文件。 站点地图和索引文件都将重定向到sitemap.php文件,该文件将使用文件名模式( $_SERVER['REQUEST_URI'] )找出要显示的列表。

文件名模式如下:

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

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 /

我专门为站点地图插入的行是:

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

否则,其他所有内容都是您的标准Web应用程序。

-编辑-

好的,所以经过大量的头部抓挠后,我发现了问题所在。 首先,我略微简化了该规则,因为我不需要捕获模式匹配,只需要一个肯定的响应,新规则是:

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

因此,踢球者只是在交换它和下面一个的顺序:

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

我现在暂时不提问题,因为我想知道为什么会有所作为。 谢谢。

此规则是多余的,应删除:

RewriteRule ^.*$ - [NC,L]

修改您的代码为此:

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