1

I would like to be able to assign dynamic subdomains to every company that signs up on my website. I know this question has been asked many times on Stackoverflow (e.g. Dynamic creation of subdomains), but those solutions are not working for me. I might have something else going wrong somewhere, hence I created a new thread.

I would like to be able to have URLs like this:

http://mycompany.testing.com/office

My site is in a subdirectory like this:

htdocs/office

I have my urlManager setup like this:

'urlManager' => array(
    'urlFormat' => 'path',
    'showScriptName' => false,
    'rules' => array(
        'http://<company:\w+>.testing.com/office' => 'office',
        '/<action:\w+>' => '/index/<action>',
        '<controller:\w+>/<id:\d+>' => '<controller>/view',
        '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
        '<controller:\w+>/<action:\w+>' => '<controller>/<action>',
    ),
)

My apache virtual host entry looks like this:

<VirtualHost *.testing.com>
        ...
    DocumentRoot "C:/xampp/htdocs/office"
    ServerName www.testing.com
    ServerAlias *.testing.com
    <Directory "C:/xampp/htdocs/office">
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

I added 127.0.0.1 *.testing.com in my Windows hosts file. And my htaccess file looks like this:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

I have tried following the Yii guide (which shows this as a very simple task), but I think I might have messed up something outside the application itself.

Any input will be highly appreciated :-)

Have a good day.

Community
  • 1
  • 1
Sthe
  • 2,575
  • 2
  • 31
  • 48
  • can you tell **how** is it not working, atm? – bool.dev Sep 09 '12 at 11:43
  • 2
    Thanks. It completely ignores the virtual host settings (and I guess the wildcard in the `host` file) and tries to lookup `http://mycompany.testing.com` online rather. – Sthe Sep 09 '12 at 12:08
  • have you looked at [this](http://stackoverflow.com/a/272092/720508) ? – bool.dev Sep 09 '12 at 13:29
  • 1
    I've tried those solutions and I get `Could not resolve host name *.testing.com -- ignoring!` in `error.log` (Apache), so I thought the `hosts` file doesn't support wildcards. I installed Acrylic DNS Proxy and added `127.0.0.1 *.testing.com`. No luck still. It just continues to try and connect to the internet. – Sthe Sep 10 '12 at 19:16
  • Just a wild guess - have you made sure that vhosts are enabled in your Apache configuration? The line should _NOT_ be commented out. – Grampa Oct 18 '12 at 09:57
  • Yeah. I have a lot of other virtual host setups running. This is just the only one that doesn't work. – Sthe Oct 19 '12 at 07:23

1 Answers1

0

By default Windows hosts file doesn't accept wildcard domains. However, there is an alternative for hosts file.

It that's just your test server, simplest solution is to add a few testing subdomains to your hosts file and that should work (mycompany1.testing.com, mycompany2.testing.com ...).

Community
  • 1
  • 1
B-Scan
  • 306
  • 3
  • 11