views:

38

answers:

2

I have a mobile site at m.site.org and the main site at site.org I am using htaccess to redirect other pages but not sure if it's useful in this case.

If people are on a mobile phone and they go to the main site I want them to be redirected to the mobile version. Once on the mobile version we have an option to go back to the full site so I don't want them stuck in a redirect loop and can't go to the main desktop version.

I can not use server-side code and would like to know if there were an option without JavaScript (doubtful).

EDIT:

The link site.org I would like redirected but NOT site.org/index.html through htaccess. Possible? Does this help?

A: 

Without touching the server, or adding JS, it's going to be difficult.

If you can check for the HTTP_USER_AGENT header on your server, you could display a HTML redirect:

<meta http-equiv="Refresh" content="0;URL=http://m.site.org" />
Lekensteyn
I have JS checking the User Agent to switch out CSS for older and newer phones. But that is only on the mobile version. I only want them redirected from going to site.org but NOT site.org/index.html is that possible?
Bry4n
That would be a .htaccess redirect or a serverscript.You can do that with JS too, but I don't think that's suitable here.Keep in mind that the mobile clients are not powerful machines, and every byte counts. So avoid displaying the slow PC page, instead redirect visitors to your mobile version using .htaccess / a serverscript.You can make a custom homepage (say index.htm) with the given <meta>-tag, and use the website given by SB (http://detectmobilebrowser.com/).
Lekensteyn
+1  A: 

You should check this out. It provides regular expressions you use against the user-agent that can be done client side, and it is open source.

You can download an htaccess or get JS from it. Then edit at will. The htaccess gives you a rewrite cond. JS will give you a function.

Now this won't scale if a new phone comes to the market, but it's pretty decent and you can change it as new things come. Or you can run a process that fetches and deploys the new regular expressions periodically

SB
This will redirect based on mobile or desktop. I need the mobile users to be allowed to view the regular site if they choose to.
Bry4n
You can put in logic to check the referer header to break the loop or set a cookie.
SB