Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

So, I want to create a subdomain for each client like:

user1.mydomain.com -> mydomain.com/users/user1

or at least

user1.mydomain.com -> mydomain.com

and I can grab the user1 part with php. Not a redirection, but a URL rewrite.

My problem is that this is just not working. This is my current configuration in the .htaccess file:

RewriteEngine on

RewriteCond %{HTTP_HOST} ^(www\.)?([a-z0-9-]+)\.mydomain\.com [NC]
RewriteCond %{QUERY_STRING} !^/users/
RewriteRule ^(.*)$ /index.php?/users/%2/$1

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

I have seen many answers about this but in my case nothing seems to work. I have also updated my domain zones file:

*.mydomain.com.        A         000.000.000.000

What I see when typing something like user2.mydomain.com is an error page from my hosting account, not a server error. As usual, any help will be much appreciated, I've been trying to figure out what's wrong for days now :P

Edit: It seems that the problem is more with the server configuration (Apache). If I type any subdomain, what it shows is a page from my hosting provider's server, not a server error (like 500, etc), just a page. The same page shown if I just type my website's IP in the URL bar, it goes to the default page of my hosting provider.

Thank you all for reading.

share|improve this question
1  
You can't do this very well (or at all) on normal shared hosting. You'll need a real server for your own (e.g. a VPS), and without any of that cPanel or Plesk crap. –  Michael Hampton Mar 23 '13 at 2:04

1 Answer 1

Do you have access to the Apache server configuration?

Your <VirtualHost> needs a ServerAlias covering your subdomains or this won't work.

If you wanted, you could just serve the content out of the subdomains without redirecting:

<VirtualHost *:80>
    ServerName example.com
    DocumentRoot /path/to/docroot
    # existing config
</VirtualHost>

<VirtualHost *:80>
    ServerName subdomains.example.com
    VirtualDocumentRoot /path/to/docroot/users/%1
</VirtualHost>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.