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

Php5_zce_logo

not tested in IE


Upcoming events

I will be speaking 11-03-2010: ConFoo 2010
I will be attending 12-03-2010: ConFoo 2010
I will be attending 17-04-2010: Pfcongres

Tags

1337 2008 2010 4developers accessibility AdaLovelaceDay09 advent agavi agile amsterdam apache apple article articles atk atkMetaNode audioscrobbler backwards compatibility barcelona bbc bbq beatstad belgium best practices bittorrent book books bughuntday caching cake cal evans cat cerf certificate cfp clear cms cologne common sense community conference conferences continuous integration crisis css custom datetime DbFinderPlugin decorator decorators deployment devdays development directoryindex documentation download dpc dpc09 DPC2008 dreamhost dv7 eclipse ed efficiency enterprise event events expertise ezcomponents facebook flickr framework frameworks freeze frontend fun games germany getting real google googletalk graceful degradation hack hackers hidden gem hiphop howto hp html http ibuildings icann ide imovie indy internet IPC ipc ipc08 javascript jobeet john peel joomla kubuntu left on the web lighttpd lime linux live london loudblog m2ts mac malware mambo marjolein meeting meme meta methodology microsoft movie music mysql namespace namespaces netbeans netherlands nllgg odmarco open source opinion ORM osx paradiso pavilion pear performance personal pfcongrez photo php phpabstract phpBB phpbb phpbelgium phpbenelux phpbnl10 phpgg phpitalia phpnw phpnw08 phptek phptek09 phpuk2009 phpUnderControl phpunit php|architect php|tek podcast politics portability postcrossing presentation presentations public qa recruiting refactoring review rewrite ruby on rails schedule script security seven things sfdaycgn simplexml slides smfony software sogeti solar sound standard standards static steer strings subversion symfony symfonycamp symfonyday symfonyUnderControlPlugin talk talks technology techportal tek09 telecommuting terratec terrorism testfest testing textpattern tips tld tomas unet usability usergroup validation vhost video vinyl virus warp weblogging wiki women work world world of warcraft writing xml xpath xsd yara year youtube ZCE zemanta zend zend framework zend server zend studio Zend_Form
© 2004 - 2010 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