1

我有下面的 htaccess 代码用于将移动设备重定向到网站的移动页面。但是,如果它是子域 URL,我需要它不重定向;例如:subdomain.mydomain.com 我需要进行哪些更改?

RewriteEngine On

RewriteCond %{REQUEST_URI} !^/mydomain.*$
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
RewriteRule ^(.*)$ https://mydomain.com/mobile-page.html [L,R=302]
4

1 回答 1

1

添加这些条件:

RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} !^(.+)\.mydomain\.com$ [NC]

因此,为了进行重定向,请求的主机不以www开头,并且它前面有一个子域mydomain.com(这不是www,通过第一个条件)。所以你的规则看起来像:

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(.+)\.mydomain\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/mydomain.*$
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
RewriteRule ^(.*)$ https://mydomain.com/mobile-page.html [L,R=302]
于 2013-05-23T20:06:38.847 回答