简体   繁体   English

使用htaccess重定向图像文件夹

[英]Redirect images folder using htaccess

I'm trying to redirect my images folder (specifically jpg files) to a different location when a mobile/tablet is used. 使用移动设备/平板电脑时,我试图将图像文件夹(特别是jpg文件)重定向到其他位置。 This is what I've currently got, but it keeps bringing up a 500 Internal Server Error when I view the images. 这是我目前所拥有的,但是在查看图像时,它会不断显示500 Internal Server Error。

RewriteCond %{HTTP_USER_AGENT} iphone|ipad|ipod|android|blackberry [NC]
RewriteRule ^images/(.+)\.(jpg)$ http://www.domain.co.uk/images/mobile/$1.$2 [QSA,L]

Thanks 谢谢

You're getting the error because of looping. 由于循环,您遇到了错误。 Try the below code: 试试下面的代码:

RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC] 
RewriteCond %{REQUEST_URI} !/images/ [NC]
RewriteRule \.(png|gif|jpe?g)$ images%{REQUEST_URI} [L,NC]

This will rewrite image URLs only when /images/ is not present in URI. 仅当/ images /在URI中不存在时,才会重写图像URL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM