我的域名:example.com
SubDomain:admin.example.com
我想重写所有图片网址:
admin.example.com/img/image1.jpg -> example.com/img/image1.jpg
admin.example.com/img/image2.png -> example.com/img/image2.png
admin.example.com/img/image3.gif -> example.com/img/image3.gif
这是我的.htaccess
,但不起作用:
RewriteCond %{HTTP_HOST} ^admin.example.com$
RewriteCond %{REQUEST_URI} \.(png|jpg|gif|jpeg|ico|bmp)$
RewriteRule (.*) http://example.com/%{REQUEST_URI} [R=301,L]
答案 0 :(得分:1)
这应该有效:
RewriteCond %{HTTP_HOST} ^admin.example.com$ [NC]
RewriteCond %{THE_REQUEST} /img/([^\s]+) [NC]
RewriteRule ^ http://example.com/img/%1 [NC,R=301,L]
答案 1 :(得分:0)
RewriteCond %{HTTP_HOST} ^admin.example.com
RewriteCond %{REQUEST_URI} \.(png|jpg|gif|jpeg|ico|bmp)$
RewriteRule (.*) http://example.com/%{REQUEST_URI} [R=301,L]
确认