.htaccess - DirectoryIndex for one folder

311 views Asked by At

I have a symfony backend installed on my server and in the symfony/web folder I have created a new folder "app" and there is an index.html. If I call https://example.com/app/ I'm getting 404 and with https://example.com/app/index.html it is working. I have tried to change the DirectoryIndex in the symfony .htaccess from this:

DirectoryIndex app.php

To this:

DirectoryIndex app.php index.html

But it is still not working. How can I do it that if I call example.com/app/ the index.html will be opened (just for that folder to not destroy the symfony settings)?

2

There are 2 answers

2
mykiwi On

Easiest way to do it:

# end of routing.yml
redirect_to_index:
    path: /app/?
    defaults:
        _controller: FrameworkBundle:Redirect:urlRedirect
        path: /app/index.html
        permanent: true

But it will be /app/index.html, not just /app/.

2
anubhava On

You can use this line at top of your app/.htaccess:

DirectoryIndex index.html
RewriteEngine On

RewriteCond %{THE_REQUEST} /index\.html [NC]
RewriteCond %{REQUEST_URI} ^(.*/)index\.html$ [NC]
RewriteRule ^ %1 [L,R=301,NE]

# remaining rules go below this