.htaccess 如何将对index.php和sitemap.xml的所有请求重写为sitemap.php

.htaccess 如何将对index.php和sitemap.xml的所有请求重写为sitemap.php,.htaccess,mod-rewrite,.htaccess,Mod Rewrite,请帮帮我,我已经做了两天了,都是徒劳的 此代码适用于将目录和页面重写为一个index.php页面 DirectoryIndex /index.php RewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQUEST_FILENAME} -l [OR] RewriteCond %{REQUEST_FILENAME} -d

请帮帮我,我已经做了两天了,都是徒劳的

此代码适用于将目录和页面重写为一个index.php页面

    DirectoryIndex /index.php
    RewriteEngine on
    RewriteBase /

    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d

    RewriteRule ^.*$ - [NC,L]
    RewriteRule ^(.*) /index.php [NC,L]

    RewriteRule ^/sitemap.xml sitemap.php [L]

sitemap.xml的问题在于,它必须重写为sitemap.php而不是index.php。您需要将sitemap规则置于索引规则之前。规则从上到下进行处理,一旦它遇到索引规则,因为.*将匹配sitemap.xml,它将由于[L]标志而停止进一步处理


另一个选择是只使用php和inside.php,包括sitemap.php;当$\u SERVER['REQUEST\u URI']等于sitemap.xml时。同样的结果。

是的,@Jonathan,我认为你应该把它作为答案张贴出来。移动到答案。