【问题标题】:.htaccess - DirectoryIndex for one folder.htaccess - 一个文件夹的 DirectoryIndex
【发布时间】:2018-02-07 02:36:30
【问题描述】:

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

DirectoryIndex app.php

到这里:

DirectoryIndex app.php index.html

但它仍然无法正常工作。如果我调用 example.com/app/,我该怎么做才能打开 index.html(只是为了该文件夹不会破坏 symfony 设置)?

【问题讨论】:

    标签: .htaccess symfony directoryindex


    【解决方案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
    

    【讨论】:

    • 是的,这行得通。但它还在 url 后面附加了 /index.html。如果它保留 /app/ 那就太好了
    • 检查我更新的答案。将重定向规则放在顶部,将所有规则放在我的命令行下方。然后从新的浏览器测试。
    【解决方案2】:

    最简单的方法:

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

    但它将是/app/index.html,而不仅仅是/app/

    【讨论】:

    • 如果它仍然只是 /app/ 如果你调用它会很好,后面没有 index.html。如果我调用 example.com/app(没有最后一个斜杠),使用你的解决方案,我会再次得到 404。
    • 如果你只想要/app/,是的,你需要更新.htaccess
    猜你喜欢
    • 2023-03-03
    • 1970-01-01
    • 1970-01-01
    • 2014-09-28
    • 2023-03-22
    • 2016-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多