Rewrite CI URL

I have never rewritten a URL before except to remove the index.php part of my CodeIgniter installation, and that I am doing this with the copied fragment in my .htaccess file. I did not have time to find out what this snippet does. I am basically very new to rewriting URLs.

I have a mobile version of my web application. I came to redirect mobile users to a subdomain: m.myhost.tld. However, since I use (one) CodeIgniter (install), I have to send these mobile users to the mobile controller, in my case /mobile/. Thus, the controller is always displayed in my address bar.

I just don't think this is very clean, and I'm looking for a way to rewrite the URL; but to be honest, I'm not even sure if this is possible ... hence my question. I want to get rid of the controller part /mobile. Is it possible?

Some examples:

My current mobile root folder

http://m.myhost.tld/mobile

I would like to turn this into

http://m.myhost.tld/

At the moment, when I go to http://m.myhost.tld/, it is redirected to the default controller for my CodeIgniter application, which is part of the desktop version of the web application.

Another example:

Turn

http://m.myhost.tld/mobile#mobile/about

at

http://m.myhost.tld/#mobile/about

, . , , , , . m, /mobile URL-. , m, ( www) .

, , , , , . , , , , , . , , , -;)

EDIT: , , . . //, . , , , .

.

+3
2

, - ,

config -

if ($_SERVER['SERVER_NAME'] == 'm.myhost.tld')
    $route['default_controller'] = "mobile";

, /mobile...

, ,

+2

: , , , - ,

:

RewriteCond $1!^mobile/
RewriteCond %{HTTP_HOST} ^m\.myhost\.tld
RewriteRule (.*) /mobile/$1 [L]
0
source

All Articles