2

我有一个网站,可以让我通过 URL 中的查询访问该网站的移动版本。

我想不通的是如何自动将移动用户重定向到这个版本(目前你必须添加'?useformat = mobile'才能查看)。

这是我当前的 htaccess 设置

RewriteEngine On

#MediaWiki short URL
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

#Mobile - not working?
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
RewriteRule ^([^/]*)$ /index.php?useformat=mobile&title=$1 [L]

#HTTPS redirect (site uses HTTPS)
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

对 mod_rewrite 来说有点新,之前没有做太多。

4

1 回答 1

0

您需要将其添加到您的移动规则之上:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

您需要将移动规则移到 mediawiki 规则之上,因为它在应用移动规则之前进行了重写,然后您需要将 HTTPS 规则移到其之上。所以在一起,它应该看起来像这样:

RewriteEngine On

#HTTPS redirect (site uses HTTPS)
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

#Mobile - not working?
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
RewriteRule ^([^/]*)$ /index.php?useformat=mobile&title=$1 [L]

#MediaWiki short URL
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
于 2012-06-29T07:30:27.287 回答