1

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:

  1. When I hit john.example.com I want to be able to see the same content I would see if I go to example.com/users/profile/john.

  2. When I hit mary.example.com I want to be able to see the same content I would see if I go to example.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).

Cool Guy
  • 51
  • 8
  • you must redirect that all with PHP to page – AbdulAhmad Matin Aug 27 '18 at 18:57
  • @AbdulAhmadMatin I don't want a redirection. I want to keep the URL as a subdomain and show the right content. – Cool Guy Aug 28 '18 at 15:21
  • @Vickel Is not the same question because the other one is about redirecting to controlers with the name of the subdomain (which can can be controlled manually because controllers are limited), my question is about showing the content without redirecting (rewrite rule) of specific controller and method with a parameter with a parameter equal to the subdomain (and parameters can't be manually added because they have no limits). – Cool Guy Aug 28 '18 at 15:28
  • 1
    I've retracted my close as duplicate vote – Vickel Aug 28 '18 at 22:02

0 Answers0