2017-08-29 27 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

相關問題