简体   繁体   English

.htaccess-一个文件夹的DirectoryIndex

[英].htaccess - DirectoryIndex for one folder

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. 我在服务器上安装了symfony后端,在symfony / web文件夹中,我创建了一个新文件夹“ app”,并且有一个index.html。 If I call https://example.com/app/ I'm getting 404 and with https://example.com/app/index.html it is working. 如果我拨打https://example.com/app/,我会收到404,并且使用https://example.com/app/index.html可以正常工作。 I have tried to change the DirectoryIndex in the symfony .htaccess from this: 我试图从此更改symfony .htaccess中的DirectoryIndex:

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)? 如果我调用example.com/app/,将如何打开index.html(仅在不破坏symfony设置的文件夹下)?

You can use this line at top of your app/.htaccess : 您可以在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

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/ . 但这将是/app/index.html ,而不仅仅是/app/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM