I'm attempting to produce the proper .htaccess that will let me map as a result:

http://domain.com/                --> http://domain.com/home 
http://domain.com/whatever        --> http://domain.com/home/whatever
http://user.domain.com/           --> http://domain.com/user 
http://user.domain.com/whatever   --> http://domain.com/user/whatever/

Here, someone would enter in the above Web addresses, however internally, it might be redirecting as though it were the URL around the right.

Even the subdomain could be dynamic (that's, http://user.domain.com is not a real subdomain but will be a .htaccess rewrite)

Also /house is my default controller so no subdomain would internally pressure it to /home controller and then any pathways following it (as proven in #2 example above) will be the (catch-all) function within that controller.

Like smart if your subdomain is passed it might get passed like a (catch-all) controller together with any (catch-all) functions for this (as proven in #4 example above)

Hopefully I am not asking much here however i can't appear to determine the correct .htaccess or routing rules (in Codeigniter) with this.

httpd.conf and hosts are setup all right.


Here's my .htaccess that's coming close but is playing up sooner or later:

RewriteEngine On

RewriteBase /
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f

RewriteCond %{HTTP_HOST} ^([a-z0-9-]+).domain [NC]
RewriteRule (.*) index.php/%1/$1 [QSA]

RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L,QSA]

Using the above, after i visit: http://test.domain/abc/123 this is exactly what I notice in $_SERVER var (I have removed a few of the fields):

    [REDIRECT_STATUS] => 200
    [SERVER_NAME] => test.domain
    [REDIRECT_URL] => /abc/123
    [QUERY_STRING] => 
    [REQUEST_URI] => /abc/123
    [SCRIPT_NAME] => /index.php
    [PATH_INFO] => /test/abc/123
    [PATH_TRANSLATED] => redirect:\index.php\test\test\abc\123\abc\123
    [PHP_SELF] => /index.php/test/abc/123

You can observe the road_Converted isn't correctly being created and i believe that might be messing some misconception?

This will work. Please make sure tell me whether it works:

RewriteEngine On
RewriteCond   %{HTTP_HOST}              ^[^.]+\.domain\.com$
RewriteRule   ^(.+)                     %{HTTP_HOST}$1        [C]
RewriteRule   ^([^.]+)\.domain\.com(.*) /$1$2                 [L]
RewriteRule   ^(.*)                     /home$1               [L]

Ok, In my opinion I've solved it. This is what I've to date.

First the .htaccess

RewriteEngine On

RewriteBase /

# if REQUEST_URI contains the word "user" and the
# SERVER_NAME doesn't contain a "." re-direct to the root
# The reason this is done is because of how the last two rules
# below are triggered
RewriteCond %{REQUEST_URI} (user) [NC]
RewriteCond %{SERVER_NAME} !\.
RewriteRule (.*) / [L,R=301]

# Allow files and directories to pass
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f

# Codeigniter rule for stripping index.php
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [C]

# Force wild-card subdomains to redirect.
# E.g. http://me.domain/foo/bar/123 as http://domain/user/me/index.php/foo/bar/123/bar/123/
RewriteCond %{HTTP_HOST} ^([a-z0-9-]+).domain [NC]
RewriteRule (.*) /index.php/user/%1/$1/ [L]

And lastly routes.php

// Force routing to userhome controller if URL contains the word "user"
// otherwise force everything else to home controller
$route['user/:any'] = "userhome";
$route[':any'] = "home";

As you can tell previously mentioned everything works. The only real factor I can not determine is the reason why the final arguments are repeated after i make use of a subdomain?

Basically do: http://domain/foo/bar/123

Then my PATH_INFO is proven as /foo/bar/123/ that is perfect

But when I actually do: http://me.domain/foo/bar/123

Then my PATH_INFO is proven as /user/me/index.php/foo/bar/123/bar/123/ Which typically is alright why may be the parameters repeating ultimately?

So yea overall I believe it's working. Only factor I'm going to do is have several routes for just about any remotes I increase my controllers. Unless of course there is a way around it?