1

我正在使用 codeigniter 生成一个包含 XML 数据的页面。该文件的 URL 位于 /index.php/sitemap,但我希望通过 /sitemap.xml 访问该 URL

我的.htaccess文件已经修改为允许用户访问 URL 而无需在 URL 之前输入 /index.php/。这是.htacess我正在使用的文件:

RewriteEngine On

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$ index.php/sitemap [L]

一切正常,除了 sitemap.xml 文件的重定向。我在运行 XAMPP 的 Windows 机器上

我究竟做错了什么?

4

3 回答 3

2

跳过 .htaccess 修改并改用普通路由。

$route['sitemap\.xml'] = 'sitemap';
于 2013-05-07T05:50:05.133 回答
0
RewriteRule ^.*sitemap\.xml$ index.php/sitemap [L]
RewriteRule ^(.*)$ /index.php/$1 [L]

您在到达站点地图检查之前进行匹配,因此它始终重定向到index.php.

这是用户指南中的示例:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^.*/(.*)$ /index.php/$1 [L]

您可以在标准 index.php 重写之前将站点地图检查推到那里

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^.*/sitemap\.xml$ index.php/sitemap [L]
RewriteRule ^.*/(.*)$ /index.php/$1 [L]
于 2013-05-07T02:37:05.140 回答
0

规则的顺序很重要。规则按照编写顺序进行处理。模式.*匹配所有内容,因此匹配规则

RewriteRule ^.*$ index.php [NC,L]

在所有请求到达最后一条规则之前重写所有请求。

当您将sitemap.xml规则放在顶部时,它将按预期工作。

于 2013-05-07T07:01:06.513 回答