2017-08-29 64 views
0

我在我的服务器和symfony/web文件夹中安装了symfony后端我创建了一个新文件夹“app”,并且有一个index.html。如果我打电话https://example.com/app/我得到404和https://example.com/app/index.html它正在工作。我试图在symfony的.htaccess中的DirectoryIndex从:.htaccess - 一个文件夹的DirectoryIndex

DirectoryIndex app.php 

要这样:

DirectoryIndex app.php index.html 

但它仍然没有工作。我怎么能这样做,如果我打电话example.com/app/ index.html将被打开(只是为了该文件夹不破坏symfony设置)?做

回答

0

最简单的方法:

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

但这将是/app/index.html,不只是/app/

+0

将是很好,如果它仍然只是/应用/如果你调用它,没有它背后的index.html。如果我打电话给example.com/app(没有最后一个斜杠),你的解决方案,我再次得到404。 – Nono

+0

如果你只想要'/ app /',是的,你需要更新'.htaccess' – mykiwi

1

您可以在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 
+0

是的,它工作。但它也在URL后面追加/index.html。这将是很好,如果它仍然/ app/ – Nono

+0

检查我更新的答案。将重定向规则保留在顶部,并将所有规则保留在我的命令行下方。然后从新的浏览器进行测试。 – anubhava

相关问题