Welcome Guest, Not a member yet? Register   Sign In
Dynamic subdomain routing with .htaccess in CodeIgniter 3
#1

Is it possible to route subdomains in a CodeIgniter 3 application using only .htaccess?

What I'm trying to achieve, as an example: I have mysite.localhost.com, and then I'll have multiple subdomains like client1.mysite.localhost.com, client2.mysite.localhost.com, and so on.

I need mysite.localhost.com to point to my 'Home' controller, which will be a landing page.

Then, I need all subdomains to point to mysite.localhost.com/client/, passing the subdomain as a parameter to the 'index' function of the 'client' controller.

I've tried all I could think of, without luck. The following works using plain PHP, but not in CodeIgniter (maybe because of routes.php?), it gives a 500 Internal Server Error (I'm guessing a loop, but I can't figure out how to solve it):

Code:
RewriteCond %{HTTP_HOST} !^mysite\.localhost\.com$ [NC]
RewriteCond %{HTTP_HOST} ^([a-z0-9-_]+)\.mysite\.localhost\.com$ [NC]
RewriteRule ^(.*)$ client/%1$1 [L]

To be clear, I need URL masking, not redirecting. Following the above examples, this is what I'm trying to achieve:

Code:
client1.mysite.localhost.com --> mysite.localhost.com/client/client1
client2.mysite.localhost.com --> mysite.localhost.com/client/client2
client3.mysite.localhost.com --> mysite.localhost.com/client/client3

And so on...

Thanks in advance!
Reply
#2

You can't add a subdomain in htaccess, look here:

https://stackoverflow.com/questions/1901...alhost-url
Reply




Theme © iAndrew 2016 - Forum software by © MyBB