2015-11-09 47 views
0

我想配置的.htaccess重定向URL:htaccess的重定向多PARAMS

http://domain.com/banners/images/?id=123&name=johnmartin&filename=17700_120X600.png

到新網址:

http://domain.com/uploads/image/17700_120X600.png

我試着配置如下:

RedirectMatch 301 ^/banners/images/?id=$1&name=$2&filename=$3 /uploads/image/$3 

但它沒有運行。 我該如何解決它?

+2

'Redirect'或'Rewrite'? – madforstrength

+0

php!= .htaccess,請不要用php標記它 – Epodax

回答

0

來匹配查詢字符串,你需要使用mod_rewrite:

RewriteEngine On 

RewriteCond %{QUERY_STRING} ^id=123&name=johnmartin&filename=17700_120X600.png$ [NC] 
RewriteRule ^banners/images/?$ http://domain.com/uploads/image/17700_120X600.png [NC,QSA,L,R] 

對於中對動態查詢字符串值,儘量

RewriteEngine On 

RewriteCond %{QUERY_STRING} ^id=([0-9]+)&name=([^&]+)&filename=([0-9]+)_([0-9]+)X([0-9]+).png$ [NC] 
RewriteRule ^banners/images/?$ http://domain.com/uploads/image/%3_%4X%5.png [NC,QSA,L,R]