下面是我当前的。htaccess文件。我想添加另一个条件/规则,如果对sitemap.xml的请求,则提供sitemap.php。请帮忙:)
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?filename=$1 [L,QSA]
</IfModule>
你可以显式地这样做:
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^sitemap.xml$ sitemap.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?filename=$1 [L,QSA]
</IfModule>
这样做可能会遇到问题…您应该为蜘蛛创建排除,以便它们仍然接收sitemap.xml
rewriterrule ^sitemap.xml$ public/sitemap.php [L]
确保PHP文件以xml格式加载,使用下面的代码
header('Content-Type: text/xml');