使用的.htaccess移动网站重定向到桌面版桌面版、重定向、网站、htaccess

由网友(乍见之欢不如处之不厌)分享简介:我有一个移动网站,它刚刚开始为台式机用户也是一个服务。我如何使用的.htaccess使用桌面到网站的桌面版本将用户重定向?I have a mobile site and it has just started a service for desktop users also. How do I use .htacc...

我有一个移动网站,它刚刚开始为台式机用户也是一个服务。我如何使用的.htaccess使用桌面到网站的桌面版本将用户重定向?

I have a mobile site and it has just started a service for desktop users also. How do I use .htaccess to redirect users using the desktop to the desktop version of the site?

我曾尝试简单的PHP脚本重定向到桌面版本的主页,但我想重定向到会略微高效。例如,我想重定向 http://site.com/subfolder/ 到的 http://site.com/desktop/subfolder/ 和我计算过,使用的.htaccess或许能得到这份工作完成。

I have tried simple PHP scripts to redirect to the home page of the desktop version, but I would like the redirect to be slightly more efficient. For example, I would like to redirect http://site.com/subfolder/ to http://site.com/desktop/subfolder/, and I figured that using .htaccess might be able to get the job done.

我已经试过以下,它似乎并没有工作。

I have tried the following and it doesn't seem to work.

RewriteCond %{REQUEST_URI} !^/desktop/.*$
RewriteCond %{HTTP_USER_AGENT} "!android|!blackberry|!ipad|!iphone|!ipod|!iemobile|!webos|!googlebot-mobile" [NC]
RewriteRule ^(.*)$ /desktop/ [L,R=302]

请帮忙!

推荐答案

在你的.htaccess文件请尝试以下规则:

Try these rules in your .htaccess file:

RewriteEngine on
Options +FollowSymlinks -MultiViews
RewriteCond %{REQUEST_URI} !^/desktop/ [NC]
RewriteCond %{HTTP_USER_AGENT} ^.*(MSIE.*Windows NT|Lynx|Safari|Opera|Firefox|Konqueror) [NC]
RewriteCond %{HTTP_USER_AGENT} !(^.*(Opera Mini|SymbianOS|Mobile)) [NC]
RewriteRule ^(.*)$ /desktop/$1 [L,R=302,NC]

更新(加上字preSS规则)

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
Options +FollowSymlinks -MultiViews

RewriteCond %{THE_REQUEST} !^GETs/wp-login.php [NC]
RewriteCond %{REQUEST_URI} !^/(desktop/|wp-admin/|wp-login.php) [NC]
RewriteCond %{HTTP_USER_AGENT} ^.*(MSIE.*Windows NT|Lynx|Safari|Opera|Firefox|Konqueror) [NC]
RewriteCond %{HTTP_USER_AGENT} !(^.*(Opera Mini|SymbianOS|Mobile)) [NC]
RewriteRule ^(.*)$ /desktop/$1 [L,R=302,NC]

RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(desktop/|wp-admin/|wp-login.php) [NC]
RewriteRule . /index.php [L]

</IfModule>
# END WordPress

R = 302将与重定向HTTPS状态302

R=302 will redirect with https status 302

L时可以使最后一个规则

L will make last rule

NE是无法逃避查询字符串

NE is for no escaping query string

$ 1你REQUEST_URI

$1 is your REQUEST_URI

阅读全文

相关推荐

最新文章