Multiple domains on symfony project

This post is about developing a symfony project that provides multiple applications that are reachable on multiple top level domains. That is application will share the same backend (models, data, etc.) but each site is a standalone application and has a dedicated top level domain.

Create two applications

The first step is to create two applications. Run

symfony generate:app site1
symfony generate:app site2

in your console and change the default actions, routing, etc. Same thing as usual.

Edit .htaccess

The next step is quite simple: Open your .htaccess file in /sf_project_dir/web and insert your second application to the .htaccess file (BEFORE the default RewriteRule)

RewriteCond %{HTTP_HOST} secondhost.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ site2.php [QSA,L]

That’s all!

That’s all to get it working. Each request to your second domain will be redirected to the according application. A drawback is, that your “frontend” application is still reachable on your second domain if you type in the script name directly. Since I’m not an htaccess expert, I just added some php code to my index.php:

if($_SERVER['SERVER_NAME'] != 'www.flatratesvergleich.de') {
header('Location: http://www.flatratesvergleich.de' . $_SERVER['REQUEST_URI']);
die;
}

About deepak

Name:Deepak Kumar Country:India Education:B.Tech(Mechanical Engg.), MBA(Information Technology) Expertise:ISO, CMMI, ITIL, SQA, SQC, Web Development, Business & System Analysis, Business Process Analysis & Design, E-Business(B2B,B2C), Information Management & Strategy. Technologies:PHP, CSS, JAVA,AJAX, MySQL, Oracle etc. Interested In:Quality Assurance, Freelance Web Development, System Analysis & Friends
This entry was posted in General, Symfony and tagged , , , , . Bookmark the permalink.
blog comments powered by Disqus