Page 1 of 1

redirect question

Posted: Mon Jan 18, 2010 9:03 am
by adeenutza
I need to add some non-php code to the pages of a website for beeing able to redirect the user to a different website (a mobile version) in case the page was accesed from a mobile device.

If user has javascript enabled, I can put a script that has as src a page from another website that checks with php if the device is mobile and, if it is, redirects the user with document.location.href to the mobile website.

Is there any way I can do this redirect if the user doesn't have javascript?

Thank you!

Re: redirect question

Posted: Mon Jan 18, 2010 9:13 am
by AbraCadaver
Check $_SERVER['HTTP_USER_AGENT'] and then use header() to redirect.

Re: redirect question

Posted: Tue Jan 19, 2010 12:41 am
by adeenutza
The code from the first website shouldn't contain PHP

Re: redirect question

Posted: Tue Jan 19, 2010 8:00 am
by AbraCadaver
adeenutza wrote:The code from the first website shouldn't contain PHP
Without javascript or PHP, the only way that I know of would be an .htaccess file if using Apache. You can use the RewriteCond %{HTTP_USER_AGENT} along with a RewriteRule.