【问题标题】:Redirecting feeds to another directory using .htaccess and mod_rewrite使用 .htaccess 和 mod_rewrite 将提要重定向到另一个目录
【发布时间】:2015-02-23 13:20:17
【问题描述】:

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

$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]:无法打开流:已达到重定向限制,在 /home/podcasts/public_html/castfeedvalidator/ajax/validate.php 第 243 行中止

谢谢, 迪翁

【问题讨论】:

标签: php regex .htaccess mod-rewrite redirect


【解决方案1】:

您的 RewriteCond 看起来不正确,请尝试以下规则:

RewriteEngine On
RewriteBase /

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

【讨论】:

    猜你喜欢
    • 2014-02-07
    • 2019-11-24
    • 2022-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多