带有URL的Apache RewriteMap可能包含也可能不包含查询字符串

时间:2014-06-19 14:49:03

标签: apache mod-rewrite rewrite

我们有RewriteMap,其中包含以下示例:

/home /
/index?q=video /videos
/index?q=media /media
/epic.html /epic

我们如何RewriteMap匹配可能有或可能没有附加QUERYSTRING的网址?

我们目前正在使用:

    RewriteMap mappings txt:/data/redirect_mappings
    RewriteCond ${mappings:$1|Unknown} !Unknown
    RewriteRule ^(.*)$ ${mappings:$1?%{QUERY_STRING}|$1?%{QUERY_STRING}} [L,R=301,QSD]

但是,似乎没有任何效果。我做错了什么?

1 个答案:

答案 0 :(得分:0)

试一试

RewriteMap mappings txt:/data/redirect_mappings

RewriteCond %{REQUEST_URI}?%{QUERY_STRING} (.*)
RewriteCond ${mappings:%1|NOTFOUND} !NOTFOUND
RewriteRule ^(.*)$ ${mappings:%1}? [L,R=301]

RewriteCond ${mappings:$1|NOTFOUND} !NOTFOUND
RewriteRule ^(.*)$ ${mappings:$1} [L,R=301]