Keep Server Online
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
or
A donation makes a contribution towards the costs, the time and effort that's going in this site and building.
Thank You! Steffen
Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
| |
|
Topic: Apache wildcard subdomain support |
|
Author |
|
phantom007
Joined: 06 Mar 2017 Posts: 1 Location: India
|
Posted: Tue 07 Mar '17 5:50 Post subject: Apache wildcard subdomain support |
|
|
Hello,
I am having a hard time running my application (built on laravel 5.4) on a wildcard subdomain that I have setup on my local machine (running Apache 2.4.18 on Linux Mint 18.1)
So, I have setup a vhost (domain.app) and a subdomain (sub.domain.app) for it and my apache vhost file looks like the following:
Code: |
# This is for the primary domain (domain.app)
<VirtualHost *:80>
ServerName domain.app
ServerAlias www.domain.app
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/test/domain.app/public
<Directory /var/www/html/test/domain.app/public>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
<IfModule mod_dir.c>
DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm
</IfModule>
</VirtualHost>
# This is for the subdomain (sub.domain.app)
<VirtualHost *:80>
ServerName domain.app
VirtualDocumentRoot /var/www/html/test/%0/public
ServerAlias *.domain.app
<Directory /var/www/html/test/sub.domain.app/public>
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
</Directory>
</VirtualHost>
|
This works fine for all of the following urls:
- http://domain.app
- http://domain.app/login
- http://domain.app
- http://sub.domain.app/login
But since, I want a wildcard subdomain, meaning I do not want to hardcode sub.domain.app in the vhost but want something like anything.domain.app so I tried to replace
Code: | <Directory /var/www/html/test/sub.domain.app/public> |
with
Code: | <Directory /var/www/html/test/%0/public> |
I get the following results:
- http://domain.app (works)
- http://domain.app/login (works)
- http://domain.app (works)
- http://sub.domain.app/login (404 Not found, The requested URL /login was not found on this server.)
-
Please can someone help me?
Thanks in advance |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7373 Location: Germany, Next to Hamburg
|
Posted: Tue 14 Mar '17 11:52 Post subject: |
|
|
Instead of using the real wild card I would use the default vhost to catch the rest / undefined vhost names.
<VirtualHost _default_:80> |
|
Back to top |
|
|
|
|
|
|