我正在使用 htaccess 将移动用户从桌面重定向到网站,但我一直在获取 $_GET 变量
I'm using htaccess to redirect mobile users from desktop to website but i keep getting the $_GET variables inside
这个问题可能看起来已经被问过了,我已经看到了所有问题,我一直在寻找并尝试很多答案和未获批准的答案。我已经成功地做到了,如果用户转到桌面版,它将转到移动站点,即使他们去了诸如此类的地方。
www.domain.com/aboutus
它将把他们带到
m.domain.com/?page=aboutus
所以这就是问题所在,并不是它不起作用,而是我一直在尝试从“?page=”部分的重定向中删除 $_GET 变量。
我的 .htaccess 看起来像...
<IfModule mod_rewrite.c>
RewriteEngine on
# if it is not a file or folder, rewrite to index.php?page=<value>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?page= [L,QSA]
</IfModule>
<IfModule mod_rewrite.c>
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|googlebot-mobile|iemobile|ipad|iphone|ipod|opera mobile|palmos|webos" [NC]
RewriteRule ^index.php(.*)$ http://m.domain.com/ [QSA,L]
</IfModule>
我试过为移动设备添加请求文件名,但无济于事。有些网站通过使用内置的 Google Chrome 检查元素实现了 9gag,google 将用户代理更改为选定的设备(手机)并且我已经使用那是为了测试重定向是如何进行的。所以如果我写 9gag.com/hot - 它会带我到 m.9gag.com/hot 而不是 m.9gag.com/?page=hot 或任何地方。
在此先感谢,我真的被这个困扰了。
您需要先检查移动重定向,并且需要包含请求 URI。
<IfModule mod_rewrite.c>
RewriteEngine on
# Redirect mobile requests to the mobile site
# (but don't redirect when accessing certain directories)
RewriteCond %{REQUEST_URI} !^/images [NC]
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|googlebot-mobile|iemobile|ipad|iphone|ipod|opera mobile|palmos|webos" [NC]
RewriteRule ^(.*)$ http://m.domain.com/ [R=302,L]
# If it is not a file or folder, rewrite to index.php?page=<value>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?page= [L,QSA]
</IfModule>
您可以通过将 302 更改为 301 来永久重定向。
这个问题可能看起来已经被问过了,我已经看到了所有问题,我一直在寻找并尝试很多答案和未获批准的答案。我已经成功地做到了,如果用户转到桌面版,它将转到移动站点,即使他们去了诸如此类的地方。
www.domain.com/aboutus
它将把他们带到
m.domain.com/?page=aboutus
所以这就是问题所在,并不是它不起作用,而是我一直在尝试从“?page=”部分的重定向中删除 $_GET 变量。
我的 .htaccess 看起来像...
<IfModule mod_rewrite.c>
RewriteEngine on
# if it is not a file or folder, rewrite to index.php?page=<value>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?page= [L,QSA]
</IfModule>
<IfModule mod_rewrite.c>
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|googlebot-mobile|iemobile|ipad|iphone|ipod|opera mobile|palmos|webos" [NC]
RewriteRule ^index.php(.*)$ http://m.domain.com/ [QSA,L]
</IfModule>
我试过为移动设备添加请求文件名,但无济于事。有些网站通过使用内置的 Google Chrome 检查元素实现了 9gag,google 将用户代理更改为选定的设备(手机)并且我已经使用那是为了测试重定向是如何进行的。所以如果我写 9gag.com/hot - 它会带我到 m.9gag.com/hot 而不是 m.9gag.com/?page=hot 或任何地方。
在此先感谢,我真的被这个困扰了。
您需要先检查移动重定向,并且需要包含请求 URI。
<IfModule mod_rewrite.c>
RewriteEngine on
# Redirect mobile requests to the mobile site
# (but don't redirect when accessing certain directories)
RewriteCond %{REQUEST_URI} !^/images [NC]
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|googlebot-mobile|iemobile|ipad|iphone|ipod|opera mobile|palmos|webos" [NC]
RewriteRule ^(.*)$ http://m.domain.com/ [R=302,L]
# If it is not a file or folder, rewrite to index.php?page=<value>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?page= [L,QSA]
</IfModule>
您可以通过将 302 更改为 301 来永久重定向。