Mod rewrite mod_rewrite 301重定向数百个旧的非结构化url

Mod rewrite mod_rewrite 301重定向数百个旧的非结构化url,mod-rewrite,redirect,apache2,rewritemap,Mod Rewrite,Redirect,Apache2,Rewritemap,我需要重定向(301)数百个旧的非结构化URL到新的。旧URL具有querystring域/目录/randomtext?args=1 我有一个包含oldurl和newurl行的文件 我正在virtualhost中尝试使用RewriteMap RewriteMap mapfile txt:mapfile.txt RewriteCond ${mapfile:$1|NOT_FOUND} !NOT_FOUND RewriteRule ^(.+)$ ${mapfile:$1} [L,R=301] 是否可

我需要重定向(301)数百个旧的非结构化URL到新的。旧URL具有querystring域/目录/randomtext?args=1

我有一个包含oldurl和newurl行的文件

我正在virtualhost中尝试使用RewriteMap

RewriteMap mapfile txt:mapfile.txt
RewriteCond ${mapfile:$1|NOT_FOUND} !NOT_FOUND
RewriteRule ^(.+)$ ${mapfile:$1} [L,R=301]
是否可以在RewriteCond中包含Querystring

我这样解决:

#define map file with oldurl newurl format
RewriteMap mapfile txt:mapfile.txt
#test if request_uri?query_string is in mapfile so length is greater than ""
RewriteCond ${mapfile:$1?%{QUERY_STRING}} >""
#If matched rewrite oldurl to mapfile[key]
RewriteRule ^/(.+)$ ${mapfile:$1?%{QUERY_STRING}}? [R=301]
我认为这是可以改进的,因为缓存查找总是失败的。我想只有请求uri被缓存

重写日志

(2) init rewrite engine with requested uri /prueba
(3) applying pattern '(.*)' to uri '/prueba'
(4) RewriteCond: input='/prueba' pattern='^/$' => not-matched
(3) applying pattern '(.*)' to uri '/prueba'
(4) RewriteCond: input='/prueba' pattern='^/index.php$' => not-matched
(3) applying pattern '^/(.+)$' to uri '/prueba'
(4) RewriteCond: input='/prueba' pattern='!-f' => matched
(4) RewriteCond: input='/prueba' pattern='!-d' => matched
(4) RewriteCond: input='/prueba' pattern='!.*\.(ico|gif|jpg|jpeg|png|js|css|GIF|JPG)' =>     matched
(6) cache lookup FAILED, forcing new map lookup
(5) map lookup OK: map=mapfile[txt] key=prueba?prueba=1 -> val=/index.php
(4) RewriteCond: input='/index.php' pattern='>""' => matched
(5) cache lookup OK: map=mapfile[txt] key=prueba?prueba=1 -> val=/index.php
(2) rewrite '/prueba' -> '/index.php?'

可能是重复的谢谢你的线索。旧URL和新URL没有相关性。新URL没有查询字符串。我想要的是测试旧url(带querystring)是否在文件中并映射到新url。@Luis我不理解缓存的问题,但如果您想在一个变量中包含URI和查询字符串,那么如何从_请求变量中提取它?@KamilŠrot Thaks获取您的评论。我认为这更难与_的要求{u REQUEST}是完整的HTTP请求,如'GET/bla/index.php?args=1 HTTP/1.1'。Luis肯定是这样,但正则表达式不会太复杂。无论如何,我帮不了你多少忙,因为我没有按照你关于缓存性能的说明来做。据我所知,apache只缓存mapfile条目,因此不能通过由两个变量组成的查询来影响缓存性能