如何使用.htaccess从移动网站重定向到完整网站

用户名

以下是我使用htaccess移动重定向获得的.htaccess文件

# Check if mobile=1 is set and set cookie 'mobile' equal to 1
RewriteCond %{QUERY_STRING} (^|&)mobile=1(&|$)
RewriteRule ^ - [CO=mobile:1:%{HTTP_HOST}]

# Check if mobile=0 is set and set cookie 'mobile' equal to 0
RewriteCond %{QUERY_STRING} (^|&)mobile=0(&|$)
RewriteRule ^ - [CO=mobile:0:%{HTTP_HOST}]

# cookie can't be set and read in the same request so check
RewriteCond %{QUERY_STRING} (^|&)mobile=0(&|$)
RewriteRule ^ - [S=1]

# Check if this looks like a mobile device
RewriteCond %{HTTP:x-wap-profile} !^$ [OR]
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC,OR]
RewriteCond %{HTTP:Profile}       !^$

# Check if we're not already on the mobile site
RewriteCond %{HTTP_HOST}          !^m\.
# Check to make sure we haven't set the cookie before
RewriteCond %{HTTP:Cookie}        !\mobile=0(;|$)
# Now redirect to the mobile site
RewriteRule ^ http://m.domain.com%{REQUEST_URI} [R,L]

使用此命令将重定向到m.domain.com,就像我希望的那样。

我的问题是将用户重定向回整个站点。

有人可以向我解释一下我该如何做到这一点。

谢谢

编辑*

完整的.htaccess文件

RewriteEngine On
RewriteBase /

#https://stackoverflow.com/questions/3680463/mobile-redirect-using-htaccess
# Check if mobile=1 is set and set cookie 'mobile' equal to 1
RewriteCond %{QUERY_STRING} (^|&)mobile=1(&|$)
RewriteRule ^ - [CO=mobile:1:%{HTTP_HOST}]

# Check if mobile=0 is set and set cookie 'mobile' equal to 0
RewriteCond %{QUERY_STRING} (^|&)mobile=0(&|$)
RewriteRule ^ - [CO=mobile:0:%{HTTP_HOST}]

# cookie can't be set and read in the same request so check
RewriteCond %{QUERY_STRING} (^|&)mobile=0(&|$)
RewriteRule ^ - [S=1]

# Check if this looks like a mobile device
RewriteCond %{HTTP:x-wap-profile} !^$ [OR]
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC,OR]
RewriteCond %{HTTP:Profile}       !^$

# Check if we're not already on the mobile site
RewriteCond %{HTTP_HOST}          !^m\.
# Check to make sure we haven't set the cookie before
RewriteCond %{HTTP:Cookie}        !\mobile=0(;|$)
# Now redirect to the mobile site
RewriteRule ^ http://m.domain.com%{REQUEST_URI} [R,L]

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
阿努巴瓦

创建您的链接为: http://m.domain.com/some-link?mobile=0

完整的.htaccess文件:

RewriteEngine On
RewriteBase /

#http://stackoverflow.com/questions/3680463/mobile-redirect-using-htaccess
# Check if mobile=1 is set and set cookie 'mobile' equal to 1
RewriteCond %{QUERY_STRING} (^|&)mobile=1(&|$)
RewriteRule ^ - [CO=mobile:1:%{HTTP_HOST}]

# Check if mobile=0 is set and set cookie 'mobile' equal to 0
RewriteCond %{QUERY_STRING} (^|&)mobile=0(&|$)
RewriteRule ^ - [CO=mobile:0:%{HTTP_HOST}]

# cookie can't be set and read in the same request so check
RewriteCond %{QUERY_STRING} (^|&)mobile=0(&|$)
RewriteRule ^ - [S=1]

# Check if this looks like a mobile device
RewriteCond %{HTTP:x-wap-profile} !^$ [OR]
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC,OR]
RewriteCond %{HTTP:Profile}       !^$
RewriteCond %{QUERY_STRING} !^mobile=0(?:&|$)
# Check if we're not already on the mobile site
RewriteCond %{HTTP_HOST}          !^m\.
# Check to make sure we haven't set the cookie before
RewriteCond %{HTTP:Cookie}        !\mobile=0(;|$)
# Now redirect to the mobile site
RewriteRule ^ http://m.domain.com%{REQUEST_URI} [R,L]

# Go back to full site
RewriteCond %{HTTP_HOST} ^m\.
RewriteCond %{QUERY_STRING} (?:^|&)mobile=0(?:&|$)
RewriteRule ^ http://domain.com%{REQUEST_URI} [R,L]

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [NC,L]

RewriteRule ^.*$ index.php [NC,L]

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

使用.htaccess将桌面用户重定向到移动网站之外

来自分类Dev

使用媒体查询使主网站响应或重定向到新的移动网站?

来自分类Dev

如何检测用户是否在移动设备上并将他们重定向到移动网站?

来自分类Dev

我的桌面如何访问自动重定向的移动网站?

来自分类Dev

如何创建从移动设备到桌面网站的重定向?

来自分类Dev

使用.htaccess将网站完全重定向到子域

来自分类Dev

通过完整的网站链接重定向到移动网站

来自分类Dev

使用.htaccess将旧的wordpress网站页面重定向到新的php网站网址

来自分类Dev

jQuery:将用户重定向到移动网站-当用户点击进入完整网站时,是否不重定向回移动网站?

来自分类Dev

如何使用.htaccess将静态重定向到动态URL(在Wordpress网站上)

来自分类Dev

将网站重定向到移动网站以及从移动设备重定向到桌面?

来自分类Dev

将网站重定向到移动网站以及从移动设备重定向到桌面?

来自分类Dev

使用.htaccess将所有网站链接www重定向到非www并将http重定向到https

来自分类Dev

检测并重定向到移动网站

来自分类Dev

使Firefox自动重定向到移动网站

来自分类Dev

如何在移动设备上重定向到AMP版本的网站?

来自分类Dev

如何在移动设备上重定向到AMP版本的网站?

来自分类Dev

如何在不更改 URL 的情况下重定向到网站的移动版本?

来自分类Dev

.htaccess或使用php,如果设备是移动设备,标签页或任何方便的设备,如何重定向网站

来自分类Dev

在Drupal网站上使用htaccess将首页重定向到其他页面

来自分类Dev

使用.htaccess将不带扩展名的Hotlinker重定向到父网站

来自分类Dev

在Drupal网站上使用htaccess将首页重定向到其他页面

来自分类Dev

如何为移动用户代理重定向网站?

来自分类Dev

使用PHP框架显示移动网站与桌面网站

来自分类Dev

如何编写htaccess重定向我的网站?

来自分类Dev

如何通过.htaccess文件重定向网站链接?

来自分类Dev

在R中,使用read_html读取的网站被重定向。如何获取重定向到的网址?

来自分类Dev

htaccess重定向后从移动网站访问父网站的文件夹

来自分类Dev

如何跟踪/跟踪用户从移动网站到非移动网站中的购物车

Related 相关文章

  1. 1

    使用.htaccess将桌面用户重定向到移动网站之外

  2. 2

    使用媒体查询使主网站响应或重定向到新的移动网站?

  3. 3

    如何检测用户是否在移动设备上并将他们重定向到移动网站?

  4. 4

    我的桌面如何访问自动重定向的移动网站?

  5. 5

    如何创建从移动设备到桌面网站的重定向?

  6. 6

    使用.htaccess将网站完全重定向到子域

  7. 7

    通过完整的网站链接重定向到移动网站

  8. 8

    使用.htaccess将旧的wordpress网站页面重定向到新的php网站网址

  9. 9

    jQuery:将用户重定向到移动网站-当用户点击进入完整网站时,是否不重定向回移动网站?

  10. 10

    如何使用.htaccess将静态重定向到动态URL(在Wordpress网站上)

  11. 11

    将网站重定向到移动网站以及从移动设备重定向到桌面?

  12. 12

    将网站重定向到移动网站以及从移动设备重定向到桌面?

  13. 13

    使用.htaccess将所有网站链接www重定向到非www并将http重定向到https

  14. 14

    检测并重定向到移动网站

  15. 15

    使Firefox自动重定向到移动网站

  16. 16

    如何在移动设备上重定向到AMP版本的网站?

  17. 17

    如何在移动设备上重定向到AMP版本的网站?

  18. 18

    如何在不更改 URL 的情况下重定向到网站的移动版本?

  19. 19

    .htaccess或使用php,如果设备是移动设备,标签页或任何方便的设备,如何重定向网站

  20. 20

    在Drupal网站上使用htaccess将首页重定向到其他页面

  21. 21

    使用.htaccess将不带扩展名的Hotlinker重定向到父网站

  22. 22

    在Drupal网站上使用htaccess将首页重定向到其他页面

  23. 23

    如何为移动用户代理重定向网站?

  24. 24

    使用PHP框架显示移动网站与桌面网站

  25. 25

    如何编写htaccess重定向我的网站?

  26. 26

    如何通过.htaccess文件重定向网站链接?

  27. 27

    在R中,使用read_html读取的网站被重定向。如何获取重定向到的网址?

  28. 28

    htaccess重定向后从移动网站访问父网站的文件夹

  29. 29

    如何跟踪/跟踪用户从移动网站到非移动网站中的购物车

热门标签

归档