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!
March 23, 2009 - tags: symfony, php, howto, apache, vhost, rewrite, directoryindex
Comments
É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 ^^

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
left: Sven: Thanks for the tip, I'll set AllowOverride to none in my virtualhost setup for this application.
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.
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
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..
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..
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
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.
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.
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!
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?

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!!!
Rentals Bunbury: Wow, symfony is a good tool which is providing many services!
Sharelord Strategy: I appreciate you for this nice article. I also use these tips to solve my problems. It's really nice post.
Shutters Brisbane: Thank you so much for sharing your information with the rest of us.
frases de amor: thanks for this information i really like this post thanks for sharing...
Maths Tutor Brisbane: I have used symphony tool. It is easy to operate and its speed is so quick.
Blinds Online: This blog is very useful for me to understand the mapping between frontend and backend. Thanks for sharing it with us.
Best-In-Bedding.com: Thanks for this useful post - I appreciate your work ! Keep on writing.
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.
Real Estate Liverpool: Which kind of mistake you did in your project? Please tell us in brief.
discount uggs boots: I am typically to running a blog and i really respect your content. The article has really peaks my interest.
Real Estate Werribee: This will aware you from the problem that you had done last time.
Family law Brisbane: Which language have you used while creating frontend and backend?
Banner Printing Brisbane: Thanks for sharing – I really found some good info here.
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.
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.