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 に答える