6

I am trying to implement static and dynamic subdomain routing in my application. It is not working as expected. I am using WAMPServer in my local machine.

routes.php

Route::get('/', 'WelcomeController@index');

Route::group(['domain' => 'api.letsplay.dev'], function () {

    Route::group(['prefix' => 'v1'], function () {
        Route::get('users', function () {
            return "Success";
        });
    });

});

php artisan route:list gives this

+------------------+----------+----------+------+----------------------------------------------+------------+
| Domain           | Method   | URI      | Name | Action                                       | Middleware |
+------------------+----------+----------+------+----------------------------------------------+------------+
|                  | GET|HEAD | /        |      | App\Http\Controllers\WelcomeController@index | guest      |
| api.letsplay.dev | GET|HEAD | v1/users |      | Closure                                      |            |
+------------------+----------+----------+------+----------------------------------------------+------------+

hosts file has this

127.0.0.1       localhost
127.0.0.1       hosp.dev
127.0.0.1       letsplay.dev

I use the .htaccess file provided by the laravel framework without any change

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

httpd-vhosts.conf

<VirtualHost *:80>
    ServerAdmin webmaster@letsplay.dev
    DocumentRoot "c:/wamp/www/letsplay-web/public"
    ServerName letsplay.dev
    ErrorLog "logs/letsplay.dev-error.log"
    CustomLog "logs/letsplay.dev-access.log" common
</VirtualHost>

When I tried to hit letsplay.dev from my browser, It is working as expected. but while trying to hit api.letsplay.dev/v1/users, I get ERR_ICANN_NAME_COLLISION in Chrome and the below error from IE!

Forbidden error from IE

Help me to understand what am I missing!

brainless
  • 5,698
  • 16
  • 59
  • 82

2 Answers2

7

Check: icannwiki

.dev is one of the new proposed gTLDs. We used to work with .dev domains internally, but moved to .local to avoid issues.

Additionally, as chanafdo mentioned in his comments, you can't use wildcards in your windows host file. So you have to specifiy each subdomain as well.

And you should generally avoid having multiple lines with the same ip address in your host file, just add them to the same line, separated by a whitespace:

127.0.0.1 localhost letsplay.dev api.letsplay.dev

To enable wildcard subdomain support in apache, just specify

ServerAlias *.letsplay.dev

in your vhost configuration.

mgrueter
  • 1,400
  • 6
  • 15
1

First enable the Apache modules alias_module and vhost_alias_module

Then in your httpd-vhosts.conf file add the following.

<VirtualHost *:80>
    ServerName letsplay.dev
    ServerAlias api.letsplay.dev
    DocumentRoot "c:/wamp/www/letsplay-web/public"
    <directory "c:/wamp/www/letsplay-web/public">
        Options Indexes FollowSymLinks
        AllowOverride all
        Order Deny,Allow
        Deny from all
        Allow from all
    </directory>
</VirtualHost>

Restart WampServer.

Then in your hosts file add the following.

127.0.0.1 api.letsplay.dev
chanafdo
  • 5,016
  • 3
  • 29
  • 46
  • How to do it for dynamic sub domain routing? – brainless Jun 08 '15 at 07:13
  • If you see the ie error screen shot, it is evident that the request is reaching the local wamp server. It is different in chrome. – brainless Jun 08 '15 at 07:15
  • What do you mean by dynamic. Do you need to do something like domain folder mapping. – chanafdo Jun 08 '15 at 07:56
  • Please note that windows does not allow wildcards in hosts file. See [this question](http://stackoverflow.com/questions/138162/wildcards-in-a-windows-hosts-file). – chanafdo Jun 08 '15 at 08:03