从移动重定向中排除文件夹

时间:2014-10-21 20:48:27

标签: regex apache .htaccess mod-rewrite redirect

我打算排除一个文件夹 www.mysite.com/ca-eng/pages/storesection/  在我的完整网站上从移动重定向,不幸的是我无法访问.htaccess文件。 我的服务提供商向我收取每次更新的费用,我已经使用了2次试验。

我准备的最新版本看起来像这样:

RewriteCond %{REQUEST_URI}!^/storesection/
RewriteRule (.*) http://mobile.mysite.com$/1 [R,L]

请告知该代码是否正常运行。

提前谢谢。

完整代码:

# stop_mobi cookie management 
RewriteCond %{QUERY_STRING} stop_mobi=yes 
RewriteRule .*- [CO=stop_mobi:yes:.mysite.com:30] 
RewriteCond %{HTTP_COOKIE} stop_mobi=yes 
RewriteCond %{QUERY_STRING} !stop_mobi=no 
RewriteRule .*- [CO=stop_mobi:yes:.mysite.com:30] 
RewriteCond %{QUERY_STRING} stop_mobi=no 
RewriteRule .*- [CO=stop_mobi:yes:.mysite.com:-30]

# mobile agents check 
RewriteCond %{HTTP_USER_AGENT} Android [OR] 
RewriteCond %{HTTP_USER_AGENT} AU-MIC [OR] 
RewriteCond %{HTTP_USER_AGENT} AUDIOVOX- [OR] 
RewriteCond %{HTTP_USER_AGENT} Alcatel [OR] 
RewriteCond %{HTTP_USER_AGENT} BB10 [OR] 
RewriteCond %{HTTP_USER_AGENT} BlackBerry [OR] 
RewriteCond %{HTTP_USER_AGENT} Blazer [OR] 
RewriteCond %{HTTP_USER_AGENT} Danger\ hiptop [OR] 
RewriteCond %{HTTP_USER_AGENT} DoCoMo/ [OR] 
RewriteCond %{HTTP_USER_AGENT} Ericsson [OR] 
RewriteCond %{HTTP_USER_AGENT} Googlebot-Mobile [OR] 
RewriteCond %{HTTP_USER_AGENT} MSN\ Mobile\ Proxy [OR] 
RewriteCond %{HTTP_USER_AGENT} Handheld [OR] 
RewriteCond %{HTTP_USER_AGENT} HTC_HD2_T58585\ Opera [OR] 
RewriteCond %{HTTP_USER_AGENT} iPhone [OR] 
RewriteCond %{HTTP_USER_AGENT} iPod [OR] 
RewriteCond %{HTTP_USER_AGENT} Klondike [OR] 
RewriteCond %{HTTP_USER_AGENT} LG- [OR] 
RewriteCond %{HTTP_USER_AGENT} LGE- [OR] 
#RewriteCond %{HTTP_USER_AGENT} \LGE\ [OR] 
RewriteCond %{HTTP_USER_AGENT} MOT- [OR] 
RewriteCond %{HTTP_USER_AGENT} NetFront [OR] 
RewriteCond %{HTTP_USER_AGENT} Nokia [OR] 
RewriteCond %{HTTP_USER_AGENT} NokiaN8 [OR] 
RewriteCond %{HTTP_USER_AGENT} Novarra-Vision [OR] 
RewriteCond %{HTTP_USER_AGENT} Opera\ Mini [OR] 
RewriteCond %{HTTP_USER_AGENT} PalmOS [OR] 
RewriteCond %{HTTP_USER_AGENT} PalmSource [OR] 
RewriteCond %{HTTP_USER_AGENT} Panasonic- [OR] 
RewriteCond %{HTTP_USER_AGENT} SAGEM- [OR] 
RewriteCond %{HTTP_USER_AGENT} SAMSUNG [OR] 
RewriteCond %{HTTP_USER_AGENT} SGH- [OR] 
RewriteCond %{HTTP_USER_AGENT} SHARP- [OR] 
RewriteCond %{HTTP_USER_AGENT} SIE- [OR] 
RewriteCond %{HTTP_USER_AGENT} Samsung- [OR] 
RewriteCond %{HTTP_USER_AGENT} Smartphone [OR] 
RewriteCond %{HTTP_USER_AGENT} Sony [OR] 
RewriteCond %{HTTP_USER_AGENT} Symbian\ OS [OR] 
RewriteCond %{HTTP_USER_AGENT} webOS [OR] 
RewriteCond %{HTTP_USER_AGENT} Windows\ CE [OR] 
RewriteCond %{HTTP_USER_AGENT} Windows\ Mobile [OR] 
RewriteCond %{HTTP_USER_AGENT} Windows\ Phone [OR] 
RewriteCond %{HTTP_USER_AGENT} nokia [OR] 
RewriteCond %{HTTP_USER_AGENT} portalmmm [OR] 
RewriteCond %{HTTP_USER_AGENT} Profile/MIDP- [OR] 
RewriteCond %{HTTP_USER_AGENT} UP.Link [OR] 
RewriteCond %{HTTP_USER_AGENT} UP.Browser [OR] 
RewriteCond %{HTTP_USER_AGENT} XV6875 
RewriteCond %{HTTP_USER_AGENT} !UsableNet [NC]

# stop_mobi check 
RewriteCond %{HTTP_COOKIE} !stop_mobi=yes 
RewriteCond %{QUERY_STRING} !stop_mobi=yes

# execute redirect 
RewriteCond %{REQUEST_URI}!^/pages/storesection/
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_URI} !\.(jpeg|gif|bmp|png|tiff|css|js)$
RewriteRule (.*) http://mobile.mysite.com$1 [R,L] 

1 个答案:

答案 0 :(得分:0)

假设.htaccess放在root中,您可以使用此规则作为第一条规则:

RewriteEngine On

RewriteCond %{REQUEST_URI} !/(ca-eng|ca-fre|us)/pages/storesection/
RewriteRule !\.(?:jpe?g|gif|bmp|png|tiff|css|js)$ http://mobile.mysite.com%{REQUEST_URI} [R,L]