如何从 Laravel 5.2 中的 url 中删除 public

app*_*ech 1 php apache .htaccess laravel laravel-5.2

我在我的共享托管服务器中使用 Laravel 5.2。我想从 url 中删除 public 而不将根目录中的 server.php 更改为 index.php,因为这样做 .env 和其他文件是公开可见的。我的 .htaccess 如下所示:

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

RewriteEngine On

# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,NC]

# Handle Front Controller...

RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /public/$1 [L,QSA]
RewriteRule ^(css|js|images|media)/(.*)$ /public/$1/$2 [L,NC]

</IfModule>
Run Code Online (Sandbox Code Playgroud)

Dhr*_*val 6

您需要将您的域从 cpanel 指向公共文件夹。

或者

将您的 .htaccess 文件从 /public 目录移动到根目录并将其内容替换为以下代码:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} -d [OR]
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^ ^$1 [N]

    RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
    RewriteRule ^(.*)$ public/$1 

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ server.php

</IfModule>
Run Code Online (Sandbox Code Playgroud)