从移动重定向中排除图像 htaccess 上



我正在使用htaccess为我的网站创建移动重定向。基本上,它 mysite.com 更改为 m.mysite.com。在此过程中,它还会更改图像的网址。我怎样才能防止这种情况发生?下面是我正在使用的代码。

    # turn on rewrite engine
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/blog/
# only detect smart phone devices if we are not on mobile site
# to prevent redirect looping
RewriteCond %{HTTP_HOST} !^m.easydestination.net$
# a bunch of smart phone devices
RewriteCond %{HTTP_USER_AGENT} "sony|symbian|nokia|samsung|mobile" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "windows ce|epoc|opera|mini|nitro" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "j2me|midp-|cldc-|netfront|mot" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "up.browser|up.link|audiovox" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "mini|nitro|j2me|midp-|cldc"[NC,OR]
RewriteCond %{HTTP_USER_AGENT} "netfront|mot|up.browser|up.link"[NC,OR]
RewriteCond %{HTTP_USER_AGENT} "audiovox|blackberry|ericsson,"[NC,OR]
RewriteCond %{HTTP_USER_AGENT} "panasonic|philips|sanyo|sharp|sie-"[NC,OR]
RewriteCond %{HTTP_USER_AGENT} "portalmmm|blazer|avantgo|dange"[NC,OR]
RewriteCond %{HTTP_USER_AGENT} "palm|series60|palmsource|pocketpc"[NC,OR]
RewriteCond %{HTTP_USER_AGENT} "smartphone|rover|ipaq|au-mic,"[NC,OR]
RewriteCond %{HTTP_USER_AGENT} "alcatel|ericy|vodafone/|wap1."[NC,OR]
RewriteCond %{HTTP_USER_AGENT} "wap2.|iPhone|android"[NC,OR]
# redirect google mobile bot
RewriteCond %{HTTP_USER_AGENT} "googlebot-mobile"[NC]
# if the request is from any one of the above devices
# redirect to mobile site
RewriteRule .? http://m.easydestination.net%{REQUEST_URI}  [L,R=302]

您可以在最后一个 RewriteRule 之前添加此行:

RewriteCond %{REQUEST_URI} !.(?:gif|jpe?g|png)$ [NC] 

排除所有带有 .gif .jpeg .jpg .png
的文件不要忘记为这些图像使用绝对链接。

最新更新