Laravel 共享主机 .htaccess

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25119493/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 09:54:15  来源:igfitidea点击:

Laravel Shared Hosting .htaccess

phpapache.htaccessmod-rewritelaravel

提问by Brent

I am trying to deploy a Laravel project onto a share hosting, I've managed to get most of the hard work done but I cannot strip off the /public directory without a Forbidden issue.

我正在尝试将 Laravel 项目部署到共享主机上,我已经设法完成了大部分艰苦的工作,但我无法在没有禁止问题的情况下剥离 /public 目录。

The website works and shows same pages for these links

该网站工作并显示这些链接的相同页面

  • www.mywebsite.com/test/index.php
  • www.mywebsite.com/test/public/
  • www.mywebsite.com/test/index.php
  • www.mywebsite.com/test/public/

But without the /index.php It returns ->

但没有 /index.php 它返回 - >

Forbidden

You don't have permission to access /test/ on this server. 

Currently my .htaccess looks like the following.

目前我的 .htaccess 如下所示。

<IfModule mod_rewrite.c>

    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ public/index.php [L]

</IfModule>

Any ideas?

有任何想法吗?

采纳答案by anubhava

Try this rule in test/.htaccess:

试试这个规则test/.htaccess

DirectoryIndex index.php
<IfModule mod_rewrite.c>

    RewriteEngine On
    RewriteBase /test/

    RewriteRule ^$ public/index.php [L]

    RewriteRule ^((?!public/).*)$ public/ [L,NC]

</IfModule>

回答by nclsvh

For me the problem was that my storage folder (and subfolders) didn't have the correct permissions.

对我来说,问题是我的存储文件夹(和子文件夹)没有正确的权限。

If you upload with FileZilla you can simply:

如果您使用 FileZilla 上传,您可以简单地:

  • right click your resources
  • go to permissions
  • check all the boxes and change the input to 777
  • 右键单击您的资源
  • 转到权限
  • 选中所有框并将输入更改为 777

Also on my host I needed to change public to httpdocs. But that might be different on your host.

同样在我的主机上,我需要将 public 更改为 httpdocs。但这在您的主机上可能有所不同。