Laravel公用文件夹子文件夹

时间:2014-12-10 13:40:55

标签: php .htaccess mod-rewrite laravel

我有像这样的laravel文件夹

  • app
  • 供应商
  • bootstrap
  • 公共
    • 文件夹
    • IMG

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

  

                 选项-MultiViews           选项 - 索引              RewriteEngine On

RewriteCond %{HTTP_HOST} ^234\.123\.1\.11
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>

2 个答案:

答案 0 :(得分:1)

我说设置一个简单的路线,就像在routes.php中那样:

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

这应该可以解决问题。编辑你的.htaccess并不是真正的nessecary除非你真的没有办法做这种事情

答案 1 :(得分:0)

将我的.htaccess更改为

  

                 选项-MultiViews           选项 - 索引              RewriteEngine On

RewriteCond %{HTTP_HOST} ^28\.42\.53\.24
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: