子域不断将其他域URL更改为子域(302) [英] Subdomain keeps changing other domain url to sub domain (302)

查看:84
本文介绍了子域不断将其他域URL更改为子域(302)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站在根域中有数据库文件。我还有一个移动域名为m.example.com



我已经包含了CORS,如果在桌面版中查看,它可以在桌面网站和移动网站上使用。但我的.htaccess文件将每个请求重定向到移动设备上的移动子域。



我正在对数据库文件进行ajax调用,但是它们被重定向为子域URL 。



喜欢

我的请求

http://example.com/folder1/file

被重定向到

http://m.example.com/folder1/file



请有人帮忙。

我的.htaccess文件是



选项+ FollowSymLinks

RewriteEngine

RewriteBase /



#写文章规则

RewriteRule ^ articles /([0-9a-zA-Z _] +)http:/ /example.com/article.php?id=$1





#检查mobile = 1是否设置并设置cookie'mobile'等于1

RewriteCond%{QUERY_STRING}(^ |&)mobile = 1(& | $)

RewriteRule ^ - [CO = mobile:1:% {HTTP_HOST}]



#检查是否设置了mobile = 0 cookie'mobile'等于0

RewriteCond%{QUERY_STRING}(^ |&)mobile = 0(& | $)

RewriteRule ^ - [CO = mobile :0:%{HTTP_HOST}]



#cookie无法在同一请求中设置和读取所以请检查

RewriteCond%{ QUERY_STRING}(^ |&)mobile = 0(& | $)

RewriteRule ^ - [S = 1]



#检查它是否像移动设备一样

RewriteCond%{HTTP:x-wap-profile}!^ $ [OR]

RewriteCond%{HTTP_USER_AGENT}android | blackberry | iphone | ipod | iemobile | opera mobile | palmos | webos | googlebot-mobile[NC,OR]

RewriteCond%{HTTP:Profile}!^ $





#检查我们是否已经不在移动网站上

RewriteCond%{HTTP_HOST}!^ m.example.com

#RewriteRule ^(。*)$ http://www.example.com/phase1/$1 [L,NC,QSA]

#检查以确保我们没有在

Rewri之前设置cookie teCond%{HTTP:Cookie}!\ mobile = 0(; | $)

#现在重定向到移动网站

RewriteRule ^ http://m.example .com%{REQUEST_URI} [R,L]



#标题

标题集Access-Control-Allow-Origin*< br $> b $ b





我希望将.htaccess排除在文件夹子域的重定向到m.example.com上。

 

解决方案

1





#检查mobile = 1是否设置并设置cookie'mobile'等于1

RewriteCond%{QUERY_STRING}( ^ |&)mobile = 1(& |




RewriteRule ^ - [CO = mobile:1:%{HTTP_HOST}]



#检查mobile = 0是否设置并设置cookie'mobile'等于0

RewriteCond%{QUERY_STRING}(^ |&)mobile = 0(& |




RewriteRule ^ - [CO = mobile:0:%{HTTP_HOS T}]



#cookie无法在同一请求中设置和读取所以请检查

RewriteCond%{QUERY_STRING}(^ | &安培)移动= 0(&安培; |

My website has database files in root domain. I also have a mobile domain as m.example.com

I already included CORS and it is working in desktop website and mobile website if viewed in desktop. But my .htaccess files redirect each request to mobile sub domain on mobile devices.

I am making ajax calls to database files but they are redirected to act like sub domain URL.

Like
my request to
http://example.com/folder1/file
is redirected to
http://m.example.com/folder1/file

Please somebody help.
My .htaccess file is

Options +FollowSymLinks
RewriteEngine on
RewriteBase /

# Write rule for articles
RewriteRule ^articles/([0-9a-zA-Z_]+) http://example.com/article.php?id=$1


# 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|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.example.com
#RewriteRule ^(.*)$ http://www.example.com/phase1/$1 [L,NC,QSA]
# 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.example.com%{REQUEST_URI} [R,L]

# Headers
Header set Access-Control-Allow-Origin "*"



I wish to exclude the .htaccess to redirection to m.example.com on folder subdomain.

解决方案

1


# 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(&|


这篇关于子域不断将其他域URL更改为子域(302)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆