I have done a jQuery mobile site. I want to upload the this directory in the original site's FTP. now i want to detect the mobile site in the mobile device only. Thats why one can only open the mobile version in mobile device only.
like i have my site url www.example.com which should be open in desktop site.
and another site means mobile site should be open in www.example/mobile site.
i have found documention of detecting mobile version like this
# don't apply the rules if you're already in the mobile directory, infintine loop
# you'll want to test against the host if you're using a subdomain
RewriteCond %{REQUEST_URI} !^/mobiledirectoryhere/.*$
# if the browser accepts these mime-types, it's definitely mobile, or pretending to be
RewriteCond %{HTTP_ACCEPT} "text\/vnd\.wap\.wml|application\/vnd\.wap\.xhtml\+xml" [NC,OR]
# a bunch of user agent tests
RewriteCond %{HTTP_USER_AGENT} "sony|symbian|nokia|samsung|mobile|windows ce|epoc|opera" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "mini|nitro|j2me|midp-|cldc-|netfront|mot|up\.browser|up\.link|audiovox"[NC,OR]
RewriteCond %{HTTP_USER_AGENT} "blackberry|ericsson,|panasonic|philips|sanyo|sharp|sie-"[NC,OR]
RewriteCond %{HTTP_USER_AGENT} "portalmmm|blazer|avantgo|danger|palm|series60|palmsource|pocketpc"[NC,OR]
RewriteCond %{HTTP_USER_AGENT} "smartphone|rover|ipaq|au-mic,|alcatel|ericy|vodafone\/|wap1\.|wap2\.|iPhone|android"[NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^$ /mobiledirectoryhere/ [L,R=302]
and i change the "mobiledirectoryhere" to my mobile version site directory "mobile". after that i upload the the file to the FTP and rename it as .htaccess
I went through the reference site http://ohryan.ca/blog/2010/04/10/how-to-detect-mobile-visitors-using-htaccess-rewrite-rules-simplified/
I got easy solution for my site detection. Simply add the .htaccess file to the root directory with the following content.
RewriteEngine on
RewriteCond %{HTTP_HOST} !^m\.myurlname\.com$
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
RewriteRule ^/?(.*)$ http://m.myurlname.com/$1 [L,R=302]
and then save it.
Related
I tried following code:-
This code is working fine when user try to access desktop web version from mobile, then this code redirecting user to mobile web version.
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} iphone|ipad|android|blackberry|windows\ phone [NC]
RewriteCond %{HTTP_HOST} ^(www)\.example\.com$
RewriteRule ^(.*) http://m.example.com
#RewriteRule ^(.*)$ %{HTTP_HOST}/$1
This code is working fine when user try to access mobile web version from desktop, then this code redirecting user to its desktop web version.
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} ^(?:(?!iphone|ipad|android|blackberry|windows\ phone).)*$
RewriteCond %{HTTP_HOST} ^(m)\.example\.com$
RewriteRule ^(.*) http://www.example.com
#RewriteRule ^(.*)$ %{HTTP_HOST}/$1
Both the code is working fine if I am using separately, but When I try to use both the code together then I am not getting desired output. Following is the result:
for 1st case: I am getting error of "example.com redirected you too many times."
for 2nd case: working fine.
I want the user to access desktop site only when he is coming from desktop, although when user try to access mobile website from desktop then the user should redirect to its desktop version. and vice versa.
Use the code 1:
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} (iphone|ipad|android|blackberry|windows\ phone) [NC]
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^ http://m.example.com
And code 2:
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} !(iphone|ipad|android|blackberry|windows\ phone) [NC]
RewriteCond %{HTTP_HOST} ^m\.example\.com$ [NC]
RewriteRule ^ http://www.example.com
I have an magento shop running (www.domain) for what i also created an speed door (Accesible through: www.domain.com/home). Now i also installed a mobile theme. the mobile theme is not on a subdomain, but due the design option in Magento, Magento recognizes mobile users en direct them to the mobile site (also just www.domain.com).
Now what i want to do is when desktop users visit www.domain.com that the are redirected to www.domain.com/home (the speeddoor) and when mobile users visit they will go to www.domain.com
I tried adding the following to .htaccess file in the Magento root, but the following code does the opposite. It redirects mobile users to domain.com/home and desktop to domain.com. how can i achieve the opposite.
#RewriteCond %{REQUEST_URI} !^/home/.*$
#RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
#RewriteRule ^(.*)$ /home/ [L,R=302]
Thanks in advance
You need a ! to indicate that you want the user-agent not to match the mobile strings:
RewriteCond %{REQUEST_URI} !^/home/.*$
RewriteCond %{HTTP_USER_AGENT} !"android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
RewriteRule ^(.*)$ /home/ [L,R=302]
I have like 10 addon domains on my main website, and atm you can visit any addon (call it test1.com) website with link as test1.mainwebsite.com or www.mainwebsite.com/test1
How can I block this access to addons?
I have tried this, but this block only www.mainwebsite.com/test1 way.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?mainwebsite.com$ [NC]
RewriteCond %{REQUEST_URI} ^/google.com/(.*)$ [OR]
RewriteCond %{REQUEST_URI} ^/something.net/(.*)$
RewriteRule ^(.*)$ - [L,R=404]
Disable access to a subdomain
The following is an example '.htaccess' code which provides a thorough means of making the Addon domain folders, and their contents, invisible through the main domain by forcing a "404 Not Found" error. This will work both for web browsers and search engines:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$ [NC]
RewriteCond %{REQUEST_URI} ^/addonfolder/(.*)$
RewriteRule ^(.*)$ - [L,R=404]
Well it's kind of hard typing a title to describe what I want to do.
Basically I have a website that I've been asked to develop a mobile site for. This website has various domains (such as .co.za,.com,.za.net) but they all run from the same folder on the server (so I only have one .htaccess file).
I want to be able to redirect the traffic that goes to www.example.co.za to m.example.co.za and traffic that goes to www.example.com to m.example.com.
How would I need to modify this .htaccess file to achieve that.
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} "alcatel|amoi|android|avantgo|blackberry|benq|cell|cricket|docomo|elaine|htc|iemobile|iphone|ipad|ipaq|ipod|j2me|java|midp|mini|mmp|mobi|motorola|nec-|nokia|palm|panasonic|philips|phone|playbook|sagem|sharp|sie-|silk|smartphone|sony|symbian|t-mobile|telus|up\.browser|up\.link|vodafone|wap|webos|wireless|xda|xoom|zte" [NC]
RewriteRule ^$ http://m.example.com/ [L,R=302]
How about:
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} "alcatel|amoi|android|avantgo|blackberry|benq|cell|cricket|docomo|elaine|htc|iemobile|iphone|ipad|ipaq|ipod|j2me|java|midp|mini|mmp|mobi|motorola|nec-|nokia|palm|panasonic|philips|phone|playbook|sagem|sharp|sie-|silk|smartphone|sony|symbian|t-mobile|telus|up\.browser|up\.link|vodafone|wap|webos|wireless|xda|xoom|zte" [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?(.*)$ [NC]
RewriteRule ^(.*)$ http://m.%2/ [L,R=302]
I've been researching my question, rewording it in many ways but I still can't seem to find an answer. It could also be that it can't be done, hopefully someone can help me. I'm pretty new to .htaccess files but I've been creating a mobile website for my company's corporate site.
What I want it to do is when you go to the mobile site, it will give you an option to see our full corporate site or the mobile site. I have it redirecting to that page just fine, but when you chose to see the full site, it will redirect you back to the same page, instead of seeing the full site. I have the mobile site in a subdirectory "www.companysite.com/mobile". Can I have it so that when you choose the option to view the full site it won't keep redirecting you to the mobile site? Here is my code right now:
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} android
RewriteRule .* http://companysite.com/mobile [R=301,L]
RewriteCond %{HTTP_USER_AGENT} BlackBerry
RewriteRule .* http://companysite.com/mobile [R=301,L]
Thank you in advance!
Some people like using cookies but it's a little more tricky. A sample solution would be:
## Setting a cookie and variable for mobile users
RewriteRule .* - [E=IsMobile:false]
RewriteRule .* - [E=MobileCookie:false]
# Mobile Redirection
# Blackberry
#RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} "blackberry" [NC]
RewriteRule ^$ http://mobile.website/ [L,R=302]
# End Blackberry
# Mobile Redirection for IPhone
RewriteCond %{HTTP_USER_AGENT} "googlebot-mobile|iemobile|iphone|ipod|opera mobile" [NC]
RewriteRule ^$ http://mobile.website/ [L,R=302]
# End other IPhone
# Mobile Redirection for other Mobile
RewriteCond %{HTTP_USER_AGENT} "android|palmos|webos" [NC]
RewriteRule ^$ http://mobile.website/ [L,R=302]
# Set isMobile variable to true
RewriteRule .* - [E=IsMobile:true]
# End other Mobile
## Assume the mobile cookie is not set:
RewriteRule .* - [E=MobileCookie:false]
## Checking for mobile cookie
RewriteCond %{HTTP_COOKIE} gpf_mobileoff=true
RewriteRule .* - [E=MobileCookie:true]
## Combining IsMobile & MobileCookie to make one rule
RewriteRule .* - [E=ShowMobile:false]
RewriteCond %{ENV:IsMobile} ^true$
RewriteCond %{ENV:MobileCookie} !^true$
RewriteRule .* - [E=ShowMobile:true]
########## End - Custom redirects
Of course you would need to change mobile.website in the code above and use js or some other method to inject a mobilecookie.
Personally, I like the HTTP_REFERRER condition more.
I think you can also check the referrer. If the referrer is your own site you don't do the redirection. Something like
RewriteCond %{HTTP_USER_AGENT} android
RewriteCond %{HTTP_REFERER} !yoursite\.com
RewriteRule .* http://companysite.com/mobile [R=301,L]
edit:
I should give the complete solution:
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} (android|BlackBerry)
RewriteCond %{HTTP_REFERER} !yoursite\.com
RewriteRule .* http://companysite.com/mobile [R=301,L]