CodeIgniter Forums
htaccess and mobile site - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: htaccess and mobile site (/showthread.php?tid=37893)



htaccess and mobile site - El Forum - 01-24-2011

[eluser]Codepeak[/eluser]
Hi!

I'm about to develop a mobile version of my CodeIgniter application.

For this I've made a new controller called "mobile" that will handle the magic.

Visiting "http://domain/mobile/index/iphone" the correct page is shown. But since that URL isn't very nice, I want to spice it up abit.

In my .htaccess (before the rewrites that CI does) I've added:

Code:
RewriteCond %{HTTP_HOST} ^m.domain [NC]
RewriteCond $1 !^(mobile)
RewriteRule ^(.*)$ index.php?/mobile/$1 [R=301]

But that doesn't do the magic.

What I'm trying to achive is to have my visitors visit "http://m.domain/index/iphone". Right now that just gives me a 404. Any tips, tricks or obvious errors that I have made?

Tnx


Edit: http://m.domain and http://domain is pointing at the same directory on the server. The "m" site works exactly like the main site w/o any problems (except the rewrite problem above).


htaccess and mobile site - El Forum - 01-24-2011

[eluser]Codepeak[/eluser]
Solved.

Code:
RewriteCond %{HTTP_HOST} ^m\.domain\.dev
RewriteCond $1 !^(mobile|index\.php)
RewriteRule ^(.*)$ /index.php?/mobile/$1 [QSA,L]



htaccess and mobile site - El Forum - 01-27-2011

[eluser]drmanny[/eluser]
Hello, Can you share the controller called “mobile”, i am looking to do the same
Thanks
Manny


htaccess and mobile site - El Forum - 01-28-2011

[eluser]Codepeak[/eluser]
Hey!

The controller is extremly simple... Just a dir called "mobile" in the application/controller/ directory.

Example of some files:

application/controller/chat.php
Handles the chat

application/controller/iphone.php
Handles iPhone frontpage

application/controller/sys.php
Handles login/logouts.

Etc...

m.domain.com/iphone/index

is rerouted using the .htaccess above to

domain.com/mobile/iphone/index

Simple as that :-)