A lot of us really do need to just RTFM sometimes.
I’ve spent a good hour googling like crazy trying to find a smooth solution to the problem of ugly Symfony URLs. For example, converting a URL that looks like this:
http://www.domain.com/backend.php/object
Into this:
http://backend.domain.com/object
It really isn’t particularly hard, but I wouldn’t recommend googling it from scratch because you’ll end up going completely mental. There are so many posts asking how to do it, but most of them are asking the wrong question, have no answers, or find an answer and never share it. Either that or it involves moving things around into sub-folders, changing routes, or doing some complex class-extending rubbish that makes your eyes bleed. If you’re here though… you’ve probably already discovered that much
So, how to rewrite your URLs without headaches in two easy steps:
1. mod_rewrite
Either in the .htaccess file in your web/ folder, or in the virtual host conf itself, add a redirect for your sub-domain to the existing rules (right above the index.php rule):
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} ^backend\..*
RewriteRule ^(.*)$ backend.php [QSA,L]
Obviously, substitute backend for your sub-domain and your front controller name.
2. The no_script_name setting
Then all you need to do is set the no_script_name setting to true in your app/backend/config/settings.yml file. For more info, check out the official documentation.
And that’s it. Clear your cache, do a little dance, and enjoy some decent URLs.
