2

We have a Symfony2 application that we wish to serve from two different domains. Here's how we want it to work;

Suppose we have two domains and two virtual hosts set on our server (we're using apache) - for the sake of argument, let's call them www.first.com and www.second.com.

Suppose the Symfony2 is hosted under the vhost for www.first.com and everything works fine.

When someone browses to www.second.com/login, for example, we wish to serve the page that can be found at www.first.com/second/login, so any request for www.second.com/* serve the page that Symfony would generate if the url was www.first.com/second/* - but, from the point of view of the user, everything should look as though it is coming from www.second.com - including cookies and web-assets.

Andrew Battye
  • 418
  • 5
  • 17
  • Aren't you going to have duplicate content? Because first.com/second/login and second.com/login will be the same, won't they – kero Jul 06 '16 at 09:28
  • What's the main point of the different domains? Do you have maybe two different databases on the different domains, but the application is the same? – cezar Jul 06 '16 at 09:41
  • Yes, the content will be the same; first.com/second/login will be the same as second.com/login - we are combining several existing web applications into a single Symfony project. One such application is currently hosted at www.second.com, but when the new Symfony version is ready, we want it to look as though it is still being served from www.second.com, even though all the code is from the new codebase. – Andrew Battye Jul 06 '16 at 09:52

2 Answers2

0

Just redirect both domain on the same Symfony app / front controller / assets.

The client browser will see two different hosts for all of them and separate cookies / assets

Alsatian
  • 3,086
  • 4
  • 25
  • 40
0

I use this apache virtual host configuration in order to achieve the same result

<VirtualHost *:80>
    DocumentRoot [your path to symfony web folder]
    <Directory [your path to symfony web folder]>
        Options FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>   
    ServerAdmin info@first.com
    ServerName www.first.com
    ServerAlias www.second.com 
    ErrorLog  /var/log/apache2/[your app name]_error.log
    CustomLog /var/log/apache2/[your app name]_access.log combined

</VirtualHost>

Pointing the two domains to the same IP of your symfony server

Edu
  • 2,520
  • 1
  • 15
  • 15
  • Thanks for that. Do you know of a way to get requests like www.second.com/login to route to www.first.com/second/login i.e. put "second" into the url that is requested on the www.first.com domain? – Andrew Battye Jul 06 '16 at 14:09
  • I don't understand what you try to do, what is the purpose of doing that? – Edu Jul 07 '16 at 09:18