Go Back   AnandTech Forums > Software > Programming

Forums
· Hardware and Technology
· CPUs and Overclocking
· Motherboards
· Video Cards and Graphics
· Memory and Storage
· Power Supplies
· Cases & Cooling
· SFF, Notebooks, Pre-Built/Barebones PCs
· Networking
· Peripherals
· General Hardware
· Highly Technical
· Computer Help
· Home Theater PCs
· Consumer Electronics
· Digital and Video Cameras
· Mobile Devices & Gadgets
· Audio/Video & Home Theater
· Software
· Software for Windows
· All Things Apple
· *nix Software
· Operating Systems
· Programming
· PC Gaming
· Console Gaming
· Distributed Computing
· Security
· Social
· Off Topic
· Politics and News
· Discussion Club
· Love and Relationships
· The Garage
· Health and Fitness
· Merchandise and Shopping
· For Sale/Trade
· Hot Deals with Free Stuff/Contests
· Black Friday 2014
· Forum Issues
· Technical Forum Issues
· Personal Forum Issues
· Suggestion Box
· Moderator Resources
· Moderator Discussions
   

Reply
 
Thread Tools
Old 02-06-2013, 10:18 AM   #1
Kracov
Member
 
Join Date: Jan 2006
Posts: 34
Default mobile site redirect with htaccess or php

I've been trying to use .htaccess for redirecting mobile users to the mobile version of my site. For two people, it doesn't seem to work.

mobile site: http://m.kracov.org

code inside .htaccess:

Code:
ErrorDocument 404 http://kracov.org/404.html

RewriteEngine On
# Check for mime types commonly accepted by mobile devices

RewriteCond %{HTTP_ACCEPT} "text/vnd.wap.wml|application/vnd.wap.xhtml+xml" [NC] RewriteCond %{REQUEST_URI} /$ RewriteRule ^  http://m.kracov.org%{REQUEST_URI} [R,L]

I also tried Mobile Detect- I searched around and someone said to put this code into the index file of my site:

Code:
<?php
@include("Mobile_Detect.php");
$detect = new Mobile_Detect();
if ($detect->isMobile() && isset($_COOKIE['mobile']))
{
$detect = "false";
}
elseif ($detect->isMobile())
{
header("Location:http://m.kracov.org");
}
?>
And also put the php file at the same location as the index file. But it just displays as text on my site. I'll admit I don't know what I'm doing.
__________________
Win 7, Firefox 13
Core 2 Duo, 1500 RAM
Kracov is offline   Reply With Quote
Old 02-12-2013, 03:15 AM   #2
watdaflip
Member
 
Join Date: Feb 2013
Posts: 25
Default

Does you index file have an extension of .php or .html?

Any PHP code will output as plain text unless the file extension is ".php" (assuming the server has PHP installed to parse .php files).

Assuming the extension was ".php", and you have PHP installed, try adding the following code:
Code:
error_reporting(E_ALL);
ini_set("display_errors", "on");
after:
Code:
<?php 
@include("Mobile_Detect.php");
In your current code.

This will ensure it outputs any PHP errors, so you can report back if that happens.

The only reasons I can see this not having redirected is either
1) PHP isn't installed, so even with a .php extension it will just display it as text
2) Somewhere in the file you include, it outputs some text, which will cause header() to fail since it has to be called before any output it sent..

Let me know and I'll see if I can help some more.
watdaflip is offline   Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 09:59 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.