Apache mod_rewrite特定的动态url


Apache mod_rewrite specific dynamic url

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

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

可以理解的是,重写并没有解决这个问题,因为它实际上是在寻找sitemap.html而不是index.php?p=站点地图。

目前的规则是:

    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www.domain.com$
    RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([^/]+)/?$ index.php?p=$1& [L,NC]

非常感谢您的帮助。

只需在两个规则之间添加此项:

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

所以这一切看起来像:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.domain.com$
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301]
RewriteRule ^sitemap'.html$ index'.php?p=sitemap [L] 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ index.php?p=$1& [L,NC]