Apache mod_rewrite 特定动态 url

Apache mod_rewrite specific dynamic url

我正在使用 mod_rewrite 写入域。com/index。php?=string 到域。com/string。当机器人出于 SEO 目的访问 sitemap.html 时,我需要让网站显示 index.php?=sitemap。我尝试了很多变体,并使用以下代码获得 /sitemap 以显示 /sitemap.html:

    RewriteRule ^sitemap/?$ http://www.domain.com/sitemap.html [R]

可以理解,重写并不能解决问题,因为它实际上是在寻找 sitemap.html 而不是 index.php?p=sitemap.

当前的规则是:

    RewriteEngine On

    RewriteCond %{HTTP_HOST} !^www.domain.com$
    RewriteRule ^(.*)$ http://www.domain.com/ [R=301]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([^/]+)/?$ index.php?p=& [L,NC]

非常感谢任何帮助。

只需在您的两个规则之间添加:

RewriteRule ^sitemap\.html$ index\.php?p=sitemap [L] 

所以它看起来像:

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www.domain.com$
RewriteRule ^(.*)$ http://www.domain.com/ [R=301]

RewriteRule ^sitemap\.html$ index\.php?p=sitemap [L] 

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ index.php?p=& [L,NC]