So, I am building a web application with symfony framework and I wanted to redirect traffic from /admin/ to my backend.php application. It was unbelievably simple yet I was unable to find very much help at the Symfony project forums.
I did get a few ideas from some pages regarding editing the routing.yml file but they were primarily about editing the routing.yml in the frontend application. Anyways, let me get on to what I did.
Now, you DO NOT have to edit anything in the /web folder except the .htaccess. Do not move the backend.php to an admin folder and rename it to index.php or anything similar. There was only 2 files you have to edit total.
Under “homepage”, “default_index” and “default”, you will will want to edit the url option like I did above. Adding “admin” before the forward slash. Just like any other symfony application, edit the param: module option to whatever module you want your backend app to go to by default.
The only thing I added here was the actual RewriteRule that catches requests for /admin and rewrites it to backend.php. The key was the additional
right before the original rewrite to the frontend controller. I say this was the key because I had the RewriteRule there before but it was not working properly until I added the RewriteCond.
Clear your symfony cache and now if you go to http://yourdomain.com you will go to your frontend app and http://yourdomain.com/admin will go to your backend app.
Enjoy and thank you for reading.