从URL, Laravel 5.2中删除index.php


Remove index.php from URL, Laravel 5.2

我看了很多例子,尝试了很多解决方案都没有成功!我想把我的项目放在Ubuntu服务器与apache。

一切正常

"/MYEXAMPLE/public/index.php/dashboard" 

但是我想:

"/MYEXAMPLE/public/dashboard"

问题就在这里!

"请求的URL/MYEXAMPLE/public/dashboard在此服务器上找不到。"

我的apache服务器已经de mod_rewrite。

我的项目文件夹是:

     - MYEXAMPLE
     --------- server.php
     --------- public
     ----------------.htaccess.php 
     ----------------.index.php 
     ---------------- views
我.htaccess.php

:

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

index . php:

<?php //

require __DIR__ . '/../bootstrap/autoload.php';

$app = require_once __DIR__ . '/../bootstrap/app.php';

$kernel = $app->make(Illuminate'Contracts'Http'Kernel::class);
$response = $kernel->handle(
        $request = Illuminate'Http'Request::capture()
);
$response->send();
$kernel->terminate($request, $response);

我不想从公共文件夹中删除视图!当我使用wamp服务器时,一切正常,我不需要在URL处使用index.php。现在我正在尝试使用Ubuntu服务器,但URL不工作,因为我需要index.php

另一个例子:如果我访问

/MYEXAMPLE/public/

/MYEXAMPLE/public/index.php

它会按我的意愿转到主页。问题是,当我试图改变到其他页面!

有什么建议可以解决这个问题吗?为什么使用wamp运行一切正常,而当我尝试使用Ubuntu服务器时,我需要URL上的index.php ?

Thanks in advance

您需要将web服务器指向public目录,并使用正常的url,如/dashboard而不是/public/index.php/dashboard

DocumentRoot "/path_to_laravel_project/public"
<Directory "/path_to_laravel_project/public">

同样,你可以在Laravel上使用这个工作的Apache虚拟主机配置:

<VirtualHost some.app:80>
    DocumentRoot "/path_to_laravel_project/public"
    ServerName some.app
    ServerAlias some.app
    <Directory "/path_to_laravel_project/public">
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

这个问题有两个解决方案。1.编辑你的。htaccess到

DirectoryIndex index.php
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::'2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^index'.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
RewriteRule .? %{ENV:BASE}/index.php [L]

2。不要编辑你的代码,只在CMD

下运行
 php artisan serve

对于这个问题我提供第二个解决方案