0

只有当目标是主页时,我才会在 .htaccess 中输入哪些代码行来执行重定向?这是这里的主要问题。我会详细说明:

我使用了以下描述的方法:Mobile Redirect using htaccess to redirect mobile。效果很好。现在,我的客户正在尝试做的是当有人在移动设备上时,如果他们试图访问不是主页(即博客)的页面,那么他们不会被重定向。因此,如果目标是主页,则重定向正常工作。说得通?

所以,我将再次简化它——仅当目标是主页时,我将在 .htaccess 中输入哪些代码行来执行重定向?

这是我所拥有的(减去检测部分)

RewriteCond %{REQUEST_URI} ^/index.php$ [OR]
RewriteCond %{REQUEST_URI} ^/$
RewriteCond %{HTTP:x-wap-profile} !^$ [OR]
RewriteCond %{HTTP:Profile}       !^$ [OR]
RewriteCond %{HTTP_USER_AGENT} "acs|alav|alca|amoi|audi|aste|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-" [NC,OR]
#there is a bunch of other user agents #
# Check if we're not already on the mobile site
RewriteCond %{HTTP_HOST}          !^m\. 
# Can not read and write cookie in same request, must duplicate condition
RewriteCond %{QUERY_STRING} !(^|&)m=0(&|$) 
# Check to make sure we haven't set the cookie before
RewriteCond %{HTTP_COOKIE}        !^.*mredir=0.*$ [NC]
# Now redirect to the mobile site
RewriteRule ^ http://m.thesiteurl.com [R,L]
4

1 回答 1

0

这前两行应该可以工作,根据您的需要替换 RewriteRule 。

RewriteCond %{REQUEST_URI} ^/index.php$ [OR]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule .* /something.php

是的,它应该像这样工作:

RewriteCond %{REQUEST_URI} ^/index.php$ [OR]
RewriteCond %{REQUEST_URI} ^/$
RewriteCond %{HTTP:x-wap-profile} !^$ [OR]
RewriteCond %{HTTP:Profile} !^$ 
RewriteCond %{HTTP_HOST} !^m\. 
RewriteCond %{HTTP:Cookie} !\smredir=0(;|$) 
RewriteRule ^ m.example.org%{REQUEST_URI} [R,L]
于 2013-01-29T14:49:28.603 回答