2011-08-18 57 views

回答

2

.htaccess规则?

如果你想所有 .xml文件指向PHP文件,使用这些。

RewriteEngine On 
RewriteBase /rss 

RewriteRule ^(.*).xml$ $1.php [R=301] 

这也应该工作:

RedirectMatch perm ^/rss/(.+)\.xml$ http://yoursite.com/rss/$1.php 

否则,使用代码杰森麦克里建议:

RewriteEngine On 
RewriteBase /rss 

RewriteRule ^rss.xml$ rss.php [L] 

这只会改写rss.xml到rss.php。

+0

我假设Apache,我不知道其他Web服务器上的解决方案。显然这是在IIS上的解决方案http://stackoverflow.com/questions/60857/mod-rewrite-equivalent-for-iis-7-0 –

+2

这是一个有点侵略性。最好是具体的,即'^ rss.xml $ rss.php [L]'否则,所有'.xml'请求将被重定向到'.php' –

+0

伟大的观点@Jason。当我做了类似的事情时,这就是我们期望的行为,但我没有考虑其他选择。 –

1

我建议通过php生成一个静态xml文件,并授予此文件的访问权限。

调用php脚本,每次读取后端数据库以生成RSS feed时,尤其是在有许多用户时,可能会影响您的服务器性能。

生成静态xml文件并在每次更新网站时进行更新。

并提供此静态xml文件的链接。

+1

好主意。内置缓存! –