【问题标题】:Laravel public folder subfolderLaravel 公用文件夹子文件夹
【发布时间】:2015-02-08 17:37:51
【问题描述】:

我有这样的 laravel 文件夹

  • 应用程序
  • 供应商
  • 引导
  • 公开
    • 文件夹
    • img

当我从 url 访问时 http://example.com/img/img.png 有效 但是当我像http://example.com/img/ 这样访问时,我得到了 Forbidden 403, 我需要的是重定向或显示该页面未找到 我的 .htaccess 看起来像这样。

选项 - 多视图 选项 - 索引 重写引擎开启

RewriteCond %{HTTP_HOST} ^1\.1\.1\.1
RewriteRule (.*) https://www.example.com/$1 [L,R=301]
RewriteCond %{HTTPS} off
# First rewrite to HTTPS:
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Now, rewrite any request to the wrong domain to use www.
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
 # Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L] </IfModule>

【问题讨论】:

    标签: php .htaccess mod-rewrite laravel


    【解决方案1】:

    我会说在 routes.php 中设置一个简单的路由,如下所示:

    Route::get("/img", function(){
        return Redirect::to('/');
    });
    

    这应该可以解决问题。编辑你的 .htaccess 并不是真正的必要,除非你真的没有其他方法来做这种事情

    【讨论】:

    • 还是没有帮助
    • 把“/img”改成“img”,可能会解决,否则我需要自己研究一下
    • 嗯,很奇怪,我建议将其发布在 laravel 论坛上,因为这应该可以。
    【解决方案2】:

    将我的 .htaccess 更改为

    选项 - 多视图 选项 - 索引 重写引擎开启

    RewriteCond %{HTTP_HOST} ^1\.1\.1\.1
    RewriteRule (.*) https://www.example.com/$1 [L,R=301]
    RewriteCond %{HTTPS} off
    # First rewrite to HTTPS:
    # Don't put www. here. If it is already there it will be included, if not
    # the subsequent rule will catch it.
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    # Now, rewrite any request to the wrong domain to use www.
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    
     # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L] </IfModule>
    

    Source:

    【讨论】:

      猜你喜欢
      • 2020-04-01
      • 1970-01-01
      • 2018-06-06
      • 1970-01-01
      • 2014-12-04
      • 2017-04-09
      • 2015-12-12
      • 1970-01-01
      • 2016-09-02
      相关资源
      最近更新 更多