After hours of researches, I still can't find the answer but I am sure there is a way to solve it.
I have got a Symfony app that features sites of my clients.
The routing is like : /app.php/{userId}/
I want to create domains (not subdomains) to point to each user page, so
domain1.com -> app.php/1/
domain2.com -> app.php/2/
etc...
But when I try to do that with Apache hosts, I get a Symfony error : "No route found for GET /". I understand why, but I cant find a solution with Apache hosts or htaccess neither with Symfony.
I dont want to duplicate my app.php or app folder.
Maybe the solution is in the htaccess...
What do you think about it ?
Thank you in advance for your ideas :)
Julien
for each hostname you can set up a virtual host that has it´s document root at your simfony app like:
<VirtualHost *:80>
ServerName domainone.com
DocumentRoot "/Projects/Project/web"
<Directory "/Projects/Project/web">
Options Indexes FollowSymLinks
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName domaintwo.com
DocumentRoot "/Projects/Project/web"
<Directory "/Projects/Project/web">
Options Indexes FollowSymLinks
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
Like ServerAlias says
you could also have one VirtualHost tag with multiple hostnames as ServerAlias
ServerName domainone.com
ServerAlias domainone.com domaintwo.com
In your symfony routing configuration you can then parse the hostname
routing_one:
resource: "#yourBundle/Resources/config/routingOne.yml"
prefix: /customerIdOne
host: "domainone.com"
routing_two:
resource: "#yourBundle/Resources/config/routingTwo.yml"
prefix: /customerIdTwo
host: "domaintwo.com"
Related
I'm using Laragon on Windows 10, and I want to create a subdomain for a new project,
The current structure is:
https://management.test
https://management.test/includes
https://management.test/client
I want to access the client folder using this URL:
https://client.management.test
But I don't want to have https://includes.management.test
I want the configuration to be only on the client folder.
I've tried playing with the Apache sites-enabled file but didn't get the result,
Can anyone share a working example with me or a simple solution to achieve this?
Thank you.
I just figured this out.
This "manual" solution worked for me
I edited drivers\etc\hosts and added my subdomain like
127.0.0.1 sub.project.test
Enable mod_vhost_alias.so in laragon\bin\apache[version]\conf\httpd.conf
Create a new file like {laragon folder}\etc\apache2\sites-enabled\sub.project.test.conf"
Add the following code in the file you just created
define ROOT "C:/laragon/htdocs/project/sub/"
define SITE "sub.project.test"
<VirtualHost *:80>
DocumentRoot ${ROOT}
ServerName ${SITE}
ServerAlias *.${SITE}
<Directory "${ROOT}">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:443>
DocumentRoot "${ROOT}"
ServerName ${SITE}
ServerAlias *.${SITE}
<Directory "${ROOT}">
AllowOverride All
Require all granted
</Directory>
SSLEngine on
SSLCertificateFile C:/laragon/etc/ssl/laragon.crt
SSLCertificateKeyFile C:/laragon/etc/ssl/laragon.key
</VirtualHost>
Replace ROOT to the path to the subdomain folder
Finally reload apache and visit the subdomain
References :
https://forum.laragon.org/topic/1705/help-subdomain-laragon/3
https://github.com/leokhoa/laragon/issues/90
I have one domain: example.com, and I need to have 2 different sites with this domain like I explain below.
Site 1: example.com
Site 2: example.com/site2
I tried to do a virtual host for each site, I show below:
Site 1 virtual host:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName example.com
DocumentRoot /var/www/html/site1/
<Directory /var/www/html/site1>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Site 2:
ServerAdmin webmaster#localhost
ServerName example.com/site2
DocumentRoot /var/www/html/site2/
<Directory /var/www/html/site2>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
However it's not working, when I type example.com it redirects me to example.com/site2 but it's showing page not found, like trying to search the page /site2 under example.com, I need it to be 2 separated websites.
Hope someone can help me.
I'm using wordpress and magento for the sites. example.com has Magento 2 and example.com/site2 has wordpress
Thanks!
A domain name cannot have slashes, information that starts with a slash begins the path section of the URL, which navigates down the website tree.
If you have two sites under the same domain name, the proper way to handle this is through subdomains. In your example that would be:
example.com
site2.example.com
You would need to update your DNS record for the domain, in this example, in the example.com's domain record, there would need to be a new A record for site2.
Then on Apache, what you are doing is fine, you would just need to change site2's ServerName:
ServerName site2.example.com
DocumentRoot /var/www/html/site2/
These two sites do not need to be in the same file structure (they don't even need to be on the same server).
I'm running an Apache server on a CentOS 7 machine.
A month ago I created a new Drupal site (let's call it site1) under /var/www/html/site1.
Visiting http://<server-ip>/site1 yielded site1 correctly.
Today, in order to provide a test environment for a new customer, I had to create a virtual host for a new Drupal site (let's call it site2).
So I created the following vhost rule:
<VirtualHost *:80>
ServerAdmin test#email.com
ServerName site2.dev
DocumentRoot /var/www/html/site2
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
</VirtualHost>
After that I created the site's folder /var/www/html/site2 and installed Drupal. Visiting http://site2.dev yields site2 correctly.
The problem is, if I now visit http://<server-ip>/site1, site2 is shown.
I can't figure out what might be the problem. The two sites are on completely different paths and different databases, so one shouldn't affect the other in my opinion.
Since I literally defined my first vhost today, I was wondering if someone might help me explain the issue. Thanks in advance!
Ok I missunderstood your problem and thought you had 2 domains.
Was your site1 accessed by the IP with no sub directory? In this case :
Change the DocumentRoot to point to /var/www/html then both sites will be accessed by IP/site1 and IP/site2.
If you were allready accessing site1 by the url IP/site1 then you had nothing to change and could access IP/site2 without your new virtualhost wich point only to site2 directory... .
Based on Laurent's answer, this is the configuration I ended up using:
# So all IP only paths continue to work
<VirtualHost *:80>
DocumentRoot /var/www/html/
ServerName 10.10.10.10 # Server's IP
<Directory /var/www/html/>
Options FollowSymLinks
AllowOverride All
</Directory>
</VirtualHost>
# So site2.dev points to its folder
<VirtualHost *:80>
DocumentRoot /var/www/html/site2
ServerName site2.dev
<Directory /var/www/html/site2>
Options FollowSymLinks
AllowOverride All
</Directory>
</VirtualHost>
I've an application deployed to EC2 using passenger and apache2.
I've registered a domain (not with AWS) and have two 'A' records pointing to my instance's elastic IP
appname.com.
*.appname.com.
In my apache2.conf file (below), I've got ServerName appname.com
The application is working perfectly when you type appname.com into a browser. But if you put www.appname.com into the browser, you just get the default apache page.
Does anyone know what I put in ServerName to handle both? I've tried adding another ServerName line under the first but it doesn't work.
Thanks for looking
/etc/apache2/apache2.conf
<IfModule mod_passenger.c>
PassengerRoot /var/lib/gems/1.9.1/gems/passenger-5.0.6
PassengerDefaultRuby /usr/bin/ruby1.9.1
</IfModule>
<VirtualHost *:80>
ServerName appname.com
# !!! Be sure to point DocumentRoot to 'public'!
DocumentRoot /home/ubuntu/projects/appname/public
ErrorLog /home/ubuntu/projects/appname/log/error.log
RailsEnv development
<Directory /home/ubuntu/projects/appname/public>
# This relaxes Apache security settings.
AllowOverride all
Require all granted
# MultiViews must be turned off.
Options -MultiViews
</Directory>
</VirtualHost>
I solved it thanks to this post (shame you can't thank on the other stack sites using your stackoverflow reputation)
Under
ServerName appname.com
you put
AliasName www.appname.com
or even better
AliasName *.appname.com
So I've set up a Amazon EC2 and registerd a few domains with 123-reg, i've set up my Apache VirtualHost But now I'm going to need to set up a few sub domains (like kitten.example.com). But it's only going to be a few, and I would like the rest of the subdomain wild cards to go to the base like this:
kitten.example.com -> kitten.example.com BUT
*.example.com -> example.com
currently my DNS with 123-reg is as follows:
www A 198.168.0.0
kitten A 198.168.0.0
* A 198.168.0.0
and my Apache httpd.conf is:
<VirtualHost *:80>
DocumentRoot "/var/www/example.com"
ServerName example.com
ServerAlias example.com
<Directory "/var/www/example.com">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/var/www/kitten.example.com"
ServerName kitten.example.com
ServerAlias kitten.example.com
<Directory "/var/www/kitten.example.com">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
so how do i redirect all those wildecard subdomains to my base domain?
You will have to map DocumentRoot and Directory to your base domain directory.
or if you wish to change the domain name also, then write a .htaccess rule for it.
Create a virtual host directive that doesn't specify the ServerName or ServerAlias. This will catch all virtual hosts on that IP address (you specifcy all IP's on port 80) that do not map to any other virtual host specification.
<VirtualHost *:80>
DocumentRoot /www/default
...
</VirtualHost>
http://httpd.apache.org/docs/2.2/vhosts/examples.html#default
However, if you want to send a 301 HTTP Header (permanently redirected), you'll need to use mod_rewrite or something similar:
http://httpd.apache.org/docs/current/mod/mod_rewrite.html
How to setup Apache mod_rewrite to redirect all but one subfolder is one good example .. needs to be modified to suit your needs if the first option isn't sufficient for your needs.