RewriteMap文本文件中的模式匹配

时间:2016-08-31 07:55:48

标签: apache .htaccess mod-rewrite

我希望使用RewriteMap在重写文本文件中进行一些模式匹配,但它似乎不起作用。以下是apache配置。

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteLog "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/logs/apache1.log"
RewriteLogLevel 5
RewriteMap lowercase int:tolower
RewriteMap escape int:escape
RewriteMap sitelevel_external "txt:C:/Program Files (x86)/Apache Software Foundation/Apache2.2/conf/html1/content/dam/redirect.txt"
RewriteCond %{REQUEST_URI} ^(.*)$
RewriteCond ${lowercase:%1} ^(.*)$
RewriteCond ${escape:%1} ^(.*)$
RewriteCond ${sitelevel_external:%1|NOT_FOUND} !NOT_FOUND
RewriteRule ^(.*) ${sitelevel_external:%1} [QSA,NC,NE,L,R=301,E=nocache:1]

redirect.txt文件内容为

^/delivery-delay.html$ http://www.yahoo.com // doesn't work
/delivery-delay.html$ http://www.yahoo.com  // doesn't work
/delivery-delay.html http://www.yahoo.com  // Works

如果我使用URL http://localhost/delivery-delay.html,只有当第三个规则在那里时才会重定向到yahoo。如果我有前两个条件,Apache不会重定向并抛出404。

Apache Logs attached

1 个答案:

答案 0 :(得分:0)

使用标准纯文本(sitelevel_external)文件无法处理正则表达式,文本文件将仅在关键映射中进行转换。

RewriteMap处理不同类型的匹配,但如果您使用文本文件,则只需查找完全匹配即可。可能External Rewriting Program可以满足您的需求,但请注意并保持简单,

  

“如果此程序挂起,则会在尝试时导致Apache挂起   使用相关的重写规则。“

相关问题