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 [email protected]
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!
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With