I reconfigured a wildcard subdomain *.example.com
and now I can access anysubdomain.example.com
and always I hit the same codeingiter installation.
I am trying to load a different content when different subdomain are requested, but I need to call always the same method and class but the parameter needs to change based on the sub domain name.
Examples:
When I hit
john.example.com
I want to be able to see the same content I would see if I go toexample.com/users/profile/john
.When I hit
mary.example.com
I want to be able to see the same content I would see if I go toexample.com/users/profile/mary
.
UPDATE:
I am using this code, but is redirecting instead of showing the content keeping the URL as a subdomain:
RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/users/profile/%1/$1 [QSA,L]
UPDATE 2:
Now I changed my .htaccess file to
RewriteCond $1 !^(index\.php|resources|robots\.txt) [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com$ [NC]
RewriteRule ^(.*)$ index.php?/users/profile/%1/$1 [L,QSA]
And when I access to username.example.com
or when I access to example.com/users/profile/username
(in both cases) and I use var_export
on $_GET
, it shows:
array (
'/users/profile/username/' => '',
)
But for some unknown reason, when I access to example.com/users/profile/username
I see the users profile (right) but when I access to username.example.com
I see the index page (I was expecting to see the users profile too).
Note: My question is not same as This question because this one is about redirecting to controllers with the name of the subdomain (which can be manually managed because controllers are limited), my question is about showing the content without redirecting (rewrite rule) of specific controller and method with a parameter equal to the subdomain (and parameters can't be manually managed because there's no a limit of values for them).