RewriteRule中的绝对路径

时间:2016-04-26 15:09:25

标签: .htaccess mod-rewrite

我需要重写的链接:

  

http://www.example.com/uploads/lu/full/00bcde2d484f1dab979c19f14b2f38bfabf13496_152_152.jpg

我的规则

RewriteEngine on
RewriteBase /

RewriteRule ^(.*)_([0-9]+)_([0-9]+)\.(jpg|jpeg|png|gif)$ http://test.mywebsite.com/themes/publisher/vignettes/resize.php?src=$1.$4&h=$2&w=$3

输出网址

  

http://test.mywebsite.com/themes/publisher/vignettes/resize.php?src=uploads/lu/full/00bcde2d484f1dab979c19f14b2f38bfabf13496.jpg&h=152&w=152

预期网址

  

http://test.mywebsite.com/themes/publisher/vignettes/resize.php?src=http://www.example.com/uploads/lu/full/00bcde2d484f1dab979c19f14b2f38bfabf13496.jpg&h=152&w=152

http://www.example.com不在我的输出网址上,我不明白为什么

1 个答案:

答案 0 :(得分:1)

您需要从始终包含完整路径的%{REQUEST_URI中捕获值:

RewriteEngine on

RewriteCond %{REQUEST_URI} ^(.*)/([^/]*?)_([0-9]+)_([0-9]+)\.(jpe?g|png|gif)$ [NC]
RewriteRule ^ http://test.mywebsite.com/themes/publisher/vignettes/resize.php?src=http://%{HTTP_HOST}%1/%2.%5&h=%3&w=%4 [L,NE,R=302]