我可以在htaccess RewriteCond中获得匹配变量吗?

时间:2011-11-01 18:13:54

标签: apache .htaccess mod-rewrite

如何在像这样的规则中访问匹配变量?

RewriteCond %{HTTP_REFERER} ^http://example\.com/dir[0-9]/?(.*)?$
RewriteRule ^images/(.*)$ other_dir(MATCHED_STRING)/images/$1 [L]

我想要网址:http://example.com/dir1 将其所有图像重定向到/ other_dir1 / images / $ 1

1 个答案:

答案 0 :(得分:2)

使用访问RewriteCond的返回引用。所以在你的例子中:

RewriteCond %{HTTP_REFERER} ^http://example\.com/dir[0-9]/?(.*)?$
RewriteRule ^images/(.*)$ other_dir%1/images/$1 [L]

%1将替换为HTTP referer中RewriteCond中匹配的内容。