Serving frontend and backend from the same document root with symfony

For quite some time I've been struggling to set up the backend of a symfony application to be served from a subdomain that is being served by the same document root, to no avail. My backend subdomain would keep serving my frontend. Today, by accident, I found out which stupid mistake prevented this from working, so I thought I'd share.

Quite often have I been staring at my virtualhost setup for the admin subdomain of this application, wondering why the hell it kept serving the frontend. I'd set the DirectoryIndex to backend.php, so why did it keep serving the frontend? There would be no reason for it to do that, it seemed to ignore my DirectoryIndex setting!

Today, for something unrelated, I opened my project's .htaccess file and realised my mistake. Apache had been configured perfectly well for all this time. Because of course, the rewrite rules in the .htaccess were configured to point to index.php!

So, I moved all the rewrite rules into both my frontend and my backend vhost, changed the backend vhost to rewrite into backend.php, and lo and behold: it worked! All this time I was not considering the .htaccess!

Now, having moved the settings into my virtualhost setup has another advantage: performance. Apache now doesn't need to parse my .htaccess anymore (which it has to do on every request) but instead parses the virtualhost at startup and then remembers the settings. So the application should be performing better as well! Double WIN!


Add comment

Comments

gravatar Éric Rogé: Tank you, I had the same issue since a long time !
Finally, no more tricks to write in the index.php

Sometimes the solution is so simple that you just don't think to it ^^
March 24, 2009
gravatar Sven: Deleting the .htaccess file does not boost performance, as Apache still has to search for this file.

If you want to disable this search (and subsequent parsing), define "AllowOverride None" in the of the DocumentRoot.

See http://httpd.apache.org/docs/2.2/mod/core.html#allowoverride
March 24, 2009
gravatar left: Sven: Thanks for the tip, I'll set AllowOverride to none in my virtualhost setup for this application.
March 24, 2009
gravatar cars vancouver bc: if your frontend and backend vhost have this problem then may be other also face this problem.this post help them to solve this problem.i really like this post.
June 17, 2011
gravatar sticker store: Keep updating us in the same way, so that we all could get amazing stuff regarding the frontend and backend issues. Try to update it a bit more. It is really tactical issue when we handle these matters from a same document root.But symfony has solved such matters
June 30, 2011
gravatar Craigslist San Francisco: i think this solution is so simple and good.this article is awesome.i like to read informative blogs and this blog is also so good and helpful.thanks for taking time to discus this topic..
October 20, 2011
gravatar Craigslist San Diego: you do good work and set up the backend of a symfony application very well.i like to read informative blogs and this blog is also so good and helpful.thanks for taking time to discus this topic..
October 27, 2011
gravatar lnyswcg: Keep updating us in the same way, so that we all could get amazing stuff regarding the frontend and backend issues. Try to update it a bit more. It is really tactical issue when we handle these matters from a same document root.But symfony has solved such matters

December 23, 2011
gravatar Discount UGG Boots: cheap uggs australia Sit down, he entered the situation. tf42srz

ugg kenly black A pleasure to see her on campus, after an absence of several years, I did not expect another case back.

affordable uggs Open the wardrobe, all simple civilian clothes, laundry and tidy, apparently brought back from home.

www.uggsaustralia.me.uk Gourmets widened eyes, understand, understand.
January 3, 2012
gravatar Foley Catheter: This is a very fine article, I think there will be countless people like it, of course, I was one of the them. I feel this article increase my awareness.
January 8, 2012
gravatar payday loans UK: I moved all the rewrite rules into both my frontend and my backend vhost, changed the backend vhost to rewrite into backend.php, and lo and behold: it worked!
January 21, 2012
gravatar car insurance quotes: Hello you I do absolutely dig your nice article, I would feel very honored if you allow me to publish a adorable review on your incredible web blog in my Blog Site would you be OK with that?

January 25, 2012
gravatar modern furniture stores phoenix az:
Hi buddy, your blog's design is simple and clean and i like it. Your blog posts are superb.Please keep them coming. Greets!!!
January 26, 2012
gravatar Rentals Bunbury: Wow, symfony is a good tool which is providing many services!
January 27, 2012
gravatar Sharelord Strategy: I appreciate you for this nice article. I also use these tips to solve my problems. It's really nice post.
January 30, 2012
gravatar Shutters Brisbane: Thank you so much for sharing your information with the rest of us.

January 31, 2012
gravatar frases de amor: thanks for this information i really like this post thanks for sharing...
January 31, 2012
gravatar Maths Tutor Brisbane: I have used symphony tool. It is easy to operate and its speed is so quick.
January 31, 2012
gravatar Blinds Online: This blog is very useful for me to understand the mapping between frontend and backend. Thanks for sharing it with us.
January 31, 2012
gravatar Best-In-Bedding.com: Thanks for this useful post - I appreciate your work ! Keep on writing.

January 31, 2012
gravatar Buy Shed: Thanks for sharing this blog with us. After reading this blog, I have solved very critical issue that I had been faced for long time.

February 1, 2012
gravatar Real Estate Liverpool: Which kind of mistake you did in your project? Please tell us in brief.
February 1, 2012
gravatar discount uggs boots: I am typically to running a blog and i really respect your content. The article has really peaks my interest. :evil:
February 1, 2012
gravatar Real Estate Werribee: This will aware you from the problem that you had done last time.
February 1, 2012
gravatar Family law Brisbane: Which language have you used while creating frontend and backend?
February 1, 2012
gravatar Banner Printing Brisbane: Thanks for sharing – I really found some good info here.

February 2, 2012
gravatar michael kors purses: These were very interesting moments and i enjoyed. This post is very informative and we can learn a lot from this post.

February 2, 2012
gravatar Gift shop: I am totally agreed about symphony tool. I had so many queries about it but after reading your blog I feel satisfied so I am very thankful to you.
February 3, 2012

Php5_zce_logo

Upcoming events

I will be speaking 06-02-2012: D-Day
I will be speaking 17-02-2012: Techademy Trainingday February
I will be speaking 23-02-2012: Zend Webinar: Git for Subversion Users

Tags

1337 2008 2010 2011 4developers access modifiers accessibility AdaLovelaceDay09 advent agavi agile alfred amsterdam apache api apple article articles atk atkMetaNode audioscrobbler automation azure backwards compatibility barcelona barcodes bash bbc bbq beatstad belgium best practices bittorrent blogging blogs boards of canada book books bughuntday bundle caching cake cal evans calendar career cat cerf certificate cfp clear cms cologne common sense communities community components conference conferences contest continuous integration contribute contribution crisis css custom d-day datetime DbFinderPlugin decorator decorators deployment devdays development directoryindex docblox doctrine documentation download dpc dpc09 dpc10 dpc11 DPC2008 dreamhost drupal dv7 eclipse ed editors efficiency enterprise errors event events expertise ezcomponents facebook finland flickr fork framework frameworks freelance freeze frontend fun game games geoip germany getting real git github gnome-do google google calendar googletalk graceful degradation hack hackers hidden gem hiphop howto hp HR html http i386 ibuildings icann ide ideasofmarch idm imovie indy ingewikkeld integration international php conference internet interview ipad IPC ipc ipc08 ipc10 ipc11se iterm2 javascript jenkins jenkins-php job job openings jobeet john peel joomla joomladays kiva kubuntu launcher launchy left on the web libraries library lighttpd lime linktuesday linux live london loudblog m2ts mac magazines malware mambo marjolein mediterra meeting meme meta methodology micro-financing microframework microsoft migration movie music mysql namespace namespaces netbeans netherlands newsfire nllgg nos odmarco open source opinion ORM osx paradiso paris partnership pavilion pear pecl performance personal pfc10 pfc11 pfcongres pfcongrez pfz photo php php5.3 phpabstract phpazure phpBB phpbb phpbelgium phpbenelux phpbnl10 phpday phpdoc phpdocumentor phpgg phpitalia phpnw phpnw08 phpnw11 phpstorm phptek phptek09 phpuk2009 phpUnderControl phpunit php|architect php|tek podcast politics portability postcrossing presentation presentations private projects protected prototype PSR-0 public python qa qr codes re2c recruiting refactoring review rewrite ruby on rails san francisco schedule scifi script security sensio seven things sfdaycgn sflive2011 shell scripting silex simplexml slides smfony software sogeti solar sound speakers spl ssh standard standards star trek static steer strings stylesheets subversion symfony symfony live Symfony2 symfonycamp symfonyday symfonylive symfonyUnderControlPlugin talk talks techademy technology techportal tek09 telecommuting terratec terrorism testfest testing textmate textpattern the right tool timeout tips tld todo tomas tools training twig uncon unet usability usergroup validation vhost video vim vinyl virus warp webinar weblogging webservices wiki windows winphp women wordpress work workshop world world of warcraft wpi writing wunderlist xml xpath xsd yara year youtube zc11 ZCE zemanta zend zend framework zend server zend studio zendcon Zend_Form zite
© 2004 - 2012 Stefan Koopmanschap + Powered by Symfony, photos powered by Flickr, links powered by Delicious, Shanghai smilies by Iconbuffet. Feeds: rss / atom. Left on the Web v4.4.0.1