Click here to Skip to main content
15,171,873 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
My website has database files in root domain. I also have a mobile domain as

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.

my request to
is redirected to

Please somebody help.
My .htaccess file is

Options +FollowSymLinks
RewriteEngine on
RewriteBase /

# Write rule for articles
RewriteRule ^articles/([0-9a-zA-Z_]+)$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} !^
#RewriteRule ^(.*)$$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 ^{REQUEST_URI} [R,L]

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

I wish to exclude the .htaccess to redirection to on folder subdomain.


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900