移动站点使用 .htaccess 重定向到桌面版本

编程入门 行业动态 更新时间:2024-10-09 12:32:53
本文介绍了移动站点使用 .htaccess 重定向到桌面版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个移动网站,它也刚刚开始为桌面用户提供服务.如何使用 .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 脚本来重定向到桌面版的主页,但我希望重定向的效率稍高一些.例如,我想将 site/subfolder/ 重定向到 site/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 site/subfolder/ to site/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]

更新(结合wordpress规则)

# 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 将制定最后的规则

NE 用于无转义查询字符串

NE is for no escaping query string

$1 是您的 REQUEST_URI

$1 is your REQUEST_URI

更多推荐

移动站点使用 .htaccess 重定向到桌面版本

本文发布于:2023-11-01 11:11:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1549180.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重定向   桌面   版本   站点   htaccess

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!