Laravel 5 .htaccess url public删除不工作

时间:2016-07-28 07:45:41

标签: php .htaccess laravel mod-rewrite xampp

我正在使用带有默认目录结构的laravel 5。 要从url中删除公用文件夹,我在.htaccess中使用以下代码

<IfModule mod_rewrite.c>
  RewriteEngine On 
  RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

我正在使用xampp,我的路径就像这个http://localhost/pro/laravel5/public

所以我的项目是在htdocs / pro / laravel5 /这里我保持在上面.htaccess 否则一切都是默认的

当我尝试访问我的项目时出现以下错误。

RouteCollection.php第145行中的NotFoundHttpException:

in RouteCollection.php line 145
at RouteCollection->match(object(Request)) in Router.php line 719
at Router->findRoute(object(Request)) in Router.php line 642
at Router->dispatchToRoute(object(Request)) in Router.php line 618
at Router->dispatch(object(Request)) in Kernel.php line 210
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 141
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in VerifyCsrfToken.php line 43
at VerifyCsrfToken->handle(object(Request), object(Closure)) in VerifyCsrfToken.php line 17
at VerifyCsrfToken->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 55
at ShareErrorsFromSession->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 61
at StartSession->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 36
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 40
at EncryptCookies->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 42
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101
at Pipeline->then(object(Closure)) in Kernel.php line 111
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 84
at Kernel->handle(object(Request)) in index.php line 53

我怎么能解决这个问题呢,我错过了什么东西.htaccess让我知道。 而且我不想使用移动文件和文件夹的第二个选项。

2 个答案:

答案 0 :(得分:0)

嘿,您必须将 .htaccess 索引文件复制到根路径,然后在htaccess文件中使用 public

<IfModule mod_rewrite.c>
   RewriteEngine On 
   RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

然后你的 index.php 全部:)

require __DIR__.'/laravel5/bootstrap/autoload.php'; and
$app = require_once __DIR__.'/laravel5/bootstrap/app.php';

答案 1 :(得分:-1)

你所要做的就是

将Laravel Project Root文件夹中的server.php重命名为index.php

将.htaccess文件从/public目录复制到Laravel根文件夹。

现在,您的项目将在您的浏览器中生效,如pro/laravel5/