繁体   English   中英

RewriteMap文本文件中的模式匹配

[英]pattern matching in RewriteMap text file

我正在寻找使用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日志

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM