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: Using Rewrite to two different document root locations |
|
Author |
|
david.livelsberger
Joined: 18 Jan 2017 Posts: 8 Location: Detroit, Michigan, USA
|
Posted: Thu 24 May '18 18:59 Post subject: Using Rewrite to two different document root locations |
|
|
I have a single cloud server that is running Craft CMS v3. Craft v3 has a feature that we want to use to have two instances (websites) on the same server and same CMS.
So, for example, I have (1) ifl.cedigital.net URL should redirect to document root /var/www/sites/ifl/web/ifl-site, while (2) alliance.cedigital.net should redirect to document root var/www/sites/ifl/web/alliance-site
Each website will have their own URL and DNS and be exposed to the Internet via their own load balancer pool. (Two separate public IP addresses.) However the cloud server will have a single private IP address.
How do I add a redirect in my single virtual host to accommodate this requirement? How do I handle variables like Servername, DocumentRoot, ErrorLog, CustomLog, etc since each website will have their own name and logs?
Thank you in advance for any help you can offer. If anybody has a better way of doing this, I am all ears! |
|
Back to top |
|
mraddi
Joined: 27 Jun 2016 Posts: 152 Location: Schömberg, Baden-Württemberg, Germany
|
Posted: Thu 24 May '18 21:42 Post subject: |
|
|
Hello David,
best approaches (in my eyes) would be to use one of the following:
* configure apache with two virtual hosts that use host-names to decide which document-root to use
* or configure apache with two virtual hosts running on two different ports and let the loadbalancers forward the requests tho the appropriate ports of the backend-cloud-webserver
With both of these approaches you are able to configure different log-files for each hostname.
If these ideas are not possible as you cannot reconfigure apache in one of the suggested ways and your only option is mod_rewrite you may use the following rule:
Code: | Rewrite On
RewriteCond %{HTTP_HOST} =ifl.cedigital.net [NC]
RewriteCond %{REQUEST_URI} !^/ifl-site/(.*)
RewriteRule ^(.*)$ /ifl-site/$1 [L]
RewriteCond %{HTTP_HOST} =alliance.cedigital.net [NC]
RewriteCond %{REQUEST_URI} !^/alliance-site/(.*)
RewriteRule ^(.*)$ /alliance-site/$1 [L] |
But with this approach I don't know how to have different log-files for each hostname.
Best regards
Matthias |
|
Back to top |
|
david.livelsberger
Joined: 18 Jan 2017 Posts: 8 Location: Detroit, Michigan, USA
|
Posted: Thu 24 May '18 22:09 Post subject: |
|
|
Matthias,
I like the idea of two vhosts.
Today, I have a a single vhost at /etc/httpd/vhosts.d/preprod.alliance.com-vhost.conf
That looks like this (I am adding just basics here)
#Virtual host #1
ServerName preprod.alliance.com
DocumentRoot "/var/www/sites/preprod.alliance.com/web/alliance-site"
ErrorLog "/var/www/logs/preprod.alliance.com-error_log"
CustomLog "/var/www/logs/preprod.alliance.com-access_log" combined
Are you telling me that I should create a second vhost and call it preprod.ifl.com-vhost.conf and add the following?
#Virtual host #2
ServerName preprod.ifl.com
DocumentRoot "/var/www/sites/preprod.ifl.com/web/ifl-site"
ErrorLog "/var/www/logs/preprod.ifl.com-error_log"
CustomLog "/var/www/logs/preprod.ifl.com-access_log" combined
Then, all traffic originating from preprod.alliance.com will be directed thru the first virtual host while traffic from preprod.ifl.com will be redirected to the second virtual host?
Thank you for your help! |
|
Back to top |
|
mraddi
Joined: 27 Jun 2016 Posts: 152 Location: Schömberg, Baden-Württemberg, Germany
|
Posted: Sun 27 May '18 8:42 Post subject: |
|
|
Hello David,
I used the following config within my apache with success:
Code: | <VirtualHost *:80>
ServerAdmin webmaster@servera.dlh.de
DocumentRoot "C:/srv/www/servera"
ServerName servera.dlh.de
#ServerAlias www.servera.dlh.de
ErrorLog "logs/servera.dlh.de-error.log"
CustomLog "logs/servera.dlh.de-access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster@serverb.dlh.de
DocumentRoot "C:/srv/www/serverb"
ServerName serverb.dlh.de
#ServerAlias www.serverb.dlh.de
ErrorLog "logs/serverb.dlh.de-error.log"
CustomLog "logs/serverb.dlh.de-access.log" common
</VirtualHost> |
Looks neraly identical to your code
Best regards
Matthias |
|
Back to top |
|
david.livelsberger
Joined: 18 Jan 2017 Posts: 8 Location: Detroit, Michigan, USA
|
Posted: Tue 29 May '18 13:41 Post subject: |
|
|
Thank you Matthias.
I am going to use your recommendation. I very much appreciate your help!
Is there some way I can mark Matthias's response as "Problem solved"? |
|
Back to top |
|
Jan-E
Joined: 09 Mar 2012 Posts: 1266 Location: Amsterdam, NL, EU
|
Posted: Wed 30 May '18 8:16 Post subject: |
|
|
david.livelsberger wrote: | Is there some way I can mark Matthias's response as "Problem solved"? |
You can edit the topic subject and add [solved] to it. |
|
Back to top |
|
david.livelsberger
Joined: 18 Jan 2017 Posts: 8 Location: Detroit, Michigan, USA
|
Posted: Mon 11 Jun '18 20:52 Post subject: |
|
|
All,
This solution is not working. Let me summarize what I have:
Two virtual hosts with two websites on a single server running Apache 2.4.
Both websites use the same document root. The developers are using a headless CMS that allows you to have one CMS for two websites. That is why I have a single document root. The websites share a single CMS instance.
Virtual host one servername is preprod.retireyourrisk.cedigital.net
Virtual Host two servername is preprod.allianceforlifetimeincome.cedigital.net
Document Root is the same for both websites.
In each virtual host, I have custom and error logs for the specific site.
I have two issues.
(1) If I do a tail -f on the access log, I see entries for both websites. If I am accessing retireyourrisk website, I should only get log entries for the retireyourrisk log??
(2) In the first virtual hosts, I have a rewrite rule to go to <document root>/campaign.html. This appears to be working using RewriteRule "^/$" "/campaign.html"
(3) In the second virtual host, I have the same rewrite rule but it goes to /alliance.html. This is not working. I am redirected to campaign.html even if I take the rewrite rule out.
What am I doing wrong? Can anybody help? I think the key here is I am using a single server for two websites that use the same document root. Within each virtual host, I rewrite to either campaign.html or alliance.html.
Thank you in advance for your help. I look forward to hear from you. |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7371 Location: Germany, Next to Hamburg
|
Posted: Wed 13 Jun '18 11:30 Post subject: |
|
|
Please post het config of the vhsots |
|
Back to top |
|
|
|
|
|
|