user676853
user676853

Reputation:

htaccess CodeIgniter Subdomains

I'm trying to setup subdomains on a website of mine but I seem to be running into a problem. I'm using CodeIgniter to handle the websites, as /site/user1

htaccess

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com
RewriteRule ^(.*)$ http://domain.com/site/%1/$1 [L,NC,QSA]

For some strange reason when it redirects it redirects to http://domain.com/site// when ever I use a subdomain for example user3.domain.com

I'm not quite sure why.

Upvotes: 1

Views: 137

Answers (1)

Panama Jack
Panama Jack

Reputation: 24478

I believe you need to do it like this.

RewriteEngine On
RewriteCond %{HTTP_HOST} !^((www\.)?)domain\.com [NC] 
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com 
RewriteRule ^(.*)$ http://domain.com/site/%1/$1 [L,NC,P]

Upvotes: 1

Related Questions