【发布时间】:2014-07-17 01:52:00
【问题描述】:
我已将此代码添加到我的 .htaccess 中
我不想重定向/img/ 文件夹...其他所有目录都希望重定向移动站点,例如这个 htaccess 代码..请给我这个代码..谢谢
我在http://www.exemple.com/img/ 文件夹中有所有图像。
当我尝试从我的手机加载这些图像时,由于重定向,路径似乎错误,即使我使用完整路径调用图像,它也无法正常工作。
/.htaccess
RewriteEngine On
RewriteBase /
#http://stackoverflow.com/questions/3680463/mobile-redirect-using-htaccess
# Check if m=1 is set and set cookie 'mobile' equal to 1
RewriteCond %{QUERY_STRING} (^|&)m=1(&|$)
RewriteRule ^ - [CO=m:1:%{HTTP_HOST}]
# Check if m=0 is set and set cookie 'mobile' equal to 0
RewriteCond %{QUERY_STRING} (^|&)m=0(&|$)
RewriteRule ^ - [CO=m:0:%{HTTP_HOST}]
# cookie can't be set and read in the same request so check
RewriteCond %{QUERY_STRING} (^|&)m=0(&|$)
RewriteRule ^ - [S=1]
# Check if this looks like a mobile device
RewriteCond %{HTTP:x-wap-profile} !^$ [OR]
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC,OR]
RewriteCond %{HTTP:Profile} !^$
RewriteCond %{QUERY_STRING} !^m=0(?:&|$)
# Check if we're not already on the mobile site
RewriteCond %{HTTP_HOST} !^m\.
# Check to make sure we haven't set the cookie before
RewriteCond %{HTTP:Cookie} !\m=0(;|$)
# Now redirect to the mobile site
RewriteRule ^ http://m.col3negmovie.com%{REQUEST_URI} [R,L]
# Go back to full site
RewriteCond %{HTTP_HOST} ^m\.
RewriteCond %{QUERY_STRING} (?:^|&)m=0(?:&|$)
RewriteRule ^ http://col3negmovie.com%{REQUEST_URI} [R,L]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
【问题讨论】:
标签: regex apache .htaccess mod-rewrite redirect