I am working on a web project that uses Symfony as it’s framework. I have mod-rewrite enabled, so all the URL requests get routed through my application’s index.php. This means that¬† www.site.com/foo/bar is actually www.site.com/index.php/foo/bar and¬† my default routing.yml settings will look for a module named “foo”and an action named “bar” in my application.
I want to host a couple of static web pages on my site independently of the rest of the Symfony driven pages. The first thing that came to mind was putting the files/folders in the project’s /web which happens to be my document root. Assuming that I created a¬† folder named “static” in /web and placed a index.html file in it, I can go to www.site.com/static/index.html and access the static html page, but¬† if all I wanted to do was to type¬† www.site.com/static/, I would get an error saying that your symfony project has no module named static.
After several hours of trying a lot different things and a reasonable amount of googling even though I wasn’t sure of¬† what I was looking for, I found many solutions and most of them involved editing Symfony’s mod rewrite configuration so that it does not try to not rewrite requests coming to your static directory. This works but can be confusing for someone who does not know the syntax for mod rewrite so I kept on searching until I came across a more elegant/simple solution. All you need to do is create a .htaccess file inside your static folder with “RewriteEngine Off” and if you want “DirectoryIndex index.html” and all your problems are solved.
Some of the search terms I used were:
mod rewrite exclude directory
symfony routing params redirect
symfony routing params
symfony routing static
apache directoryindex folder
subfolders symfony web directory