mod_rewrite的一切都送不匹配的RewriteMap指令
-
19-09-2019 - |
题
我具有与常规的东西开始一个htaccess文件:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
然后有几个重写,例如:
RewriteRule ^protect/?$ /Legal/Your-Financial-Protection.aspx [NC, L, R=301]
然后用RewriteMap指令结束时:
RewriteMap map txt:rewritemaps/map.txt [NC]
RewriteRule ^(.+)$ ${map:$1} [R=301]
在RewriteMap指令包含了所有我们的传统的URL - 将被重定向到新的网站相当于网页上我们目前的网站和短网址的网页(有4K左右,所以我需要真正使用地图):
Inspiration.aspx /Inspiration.aspx
Destinations/Africa/Countries/Gabon.aspx /Destinations/Africa/Gabon.aspx
indonesia /Destinations/Southeast-Asia/Indonesia.aspx
的问题是,在启用RewriteMap指令(即,不注释),我的所有URL(甚至是那些不匹配的)重定向到/ - 包括样式表,JS,图像等
我后是地图匹配模式的URI来重定向到更换和其他一切通过(即保持不变)。
我已经尝试在地图上设置$ 1的默认值:
RewriteRule ^(.+)$ ${map:$1|$1} [R=301]
但这只是导致重定向循环。我想我也可以跳过重写所有的.css,.js文件,JPG格式等,但宁可不要保持使用的文件扩展名列表。
通知你,我用ISAPIRewrite从HeliconTech(因为我在IIS 6),尽管它声称处理rewritemaps按照Apache和我们从来没有在过去的问题。
任何帮助,将非常感激!
谢谢,亚当
解决方案
只要把只在地图中对实际有所不同。否则,你会重定向到相同的值,并得到一个无限递归。
和仅当发现匹配时重定向,尝试:
RewriteCond ${map:$1} ^/.+
RewriteRule ^(.+)$ %0 [R=301]
其他提示
此线的问题是:
RewriteMap map txt:rewritemaps/map.txt [NC]
您不能定义在.htaccess文件一个RewriteMap指令。 (参见RewriteMap指令文档)你必须定义在服务器或虚拟主机的地图上下文,然后它可以在你的.htaccess文件中引用。如果您打开日志级别够高,你会看到你的地图没有被加载的警告。
浓汤的解决方案是伟大的,但它似乎没有处理URL与空间。 http://www.webmasterworld.com/apache/3830228.htm 提供洞察如何处理空间, 结合这两个像这样:
RewriteCond ${moved:${escape:$1}} ^/.+
RewriteRule ^(.+)$ %0 [R=301]
不工作。该死我讨厌的mod_rewrite
IPADDR - - [07/Jan/2010:01:44:58 --0500] [example.org/sid#842a5a8][rid#100e0a18/initial] (2) init rewrite engine with requested uri /press/Partners With City.pdf
IPADDR - - [07/Jan/2010:01:44:58 --0500] [example.org/sid#842a5a8][rid#100e0a18/initial] (3) applying pattern '^(.+)$' to uri '/press/Partners With City.pdf'
IPADDR - - [07/Jan/2010:01:44:58 --0500] [example.org/sid#842a5a8][rid#100e0a18/initial] (5) map lookup OK: map=escape key=/press/Partners With City.pdf -> val=/press/Partners%20With%20City.pdf
IPADDR - - [07/Jan/2010:01:44:58 --0500] [example.org/sid#842a5a8][rid#100e0a18/initial] (6) cache lookup FAILED, forcing new map lookup
IPADDR - - [07/Jan/2010:01:44:58 --0500] [example.org/sid#842a5a8][rid#100e0a18/initial] (5) map lookup FAILED: map=moved[txt] key=/press/Partners%20With%20City.pdf
IPADDR - - [07/Jan/2010:01:44:58 --0500] [example.org/sid#842a5a8][rid#100e0a18/initial] (4) RewriteCond: input='' pattern='^/.+' => not-matched
亚当,秋葵的规则包括在所述键的斜线, 和地图的发布版本缺少他们。
RewriteLogLevel 9是用于发现的东西,如这非常方便。