使用.htaccess和mod_rewrite将订阅源重定向到另一个目录

时间:2015-02-23 13:20:17

标签: php regex .htaccess mod-rewrite redirect

我想将所有Feed文件请求(* .xml)重定向到php脚本,该脚本将调整请求的url然后输出结果。我目前有一个脚本执行此操作,但最终在无限重定向循环中。我知道Apache会一遍又一遍地请求调整后的文件,除非我有条件停止它,因此我在.htaccess文件中添加了一个条件,只有当它来自root时才处理该文件。我认为这个概念很好,但仍然有同样的错误。该脚本的最后一部分如下: ...

$fileUrl = $row['file_url'] . $feedFile;
}

header('Location: ' . $fileUrl);
header('Content-type: text/xml');
header('Content-length: ' . filesize($fileUrl));
header('Content-Disposition: filename= '.$fileUrl);
header('X-Pad: avoid browser bug');
header('Cache-Control: no-cache');
readfile($fileUrl); 

>

.htaccess文件如下: 选项+ FollowSymlinks

   RewriteEngine On
   RewriteBase /
   #Only process .xml requests if they are from root
   RewriteCond %{REQUEST_URI} ^/$   
   RewriteRule ([a-zA-Z0-9]+\.xml$) checkForAuth.php?file=$1 [QSA] 

我使用castfeedvalidator得到以下错误:

警告:复制(http://www.example.com/SFAPremium.xml?name=ejleeson)[function.copy]:无法打开流:达到重定向限制,在第243行/home/podcasts/public_html/castfeedvalidator/ajax/validate.php中止

谢谢, 翁

1 个答案:

答案 0 :(得分:1)

您的RewriteCond看起来不正确,请尝试使用此规则:

RewriteEngine On
RewriteBase /

# Only process .xml requests if they are from root
RewriteRule ^([\w-]+)\.xml$ checkForAuth.php?file=$1 [NC,L,QSA] 
相关问题