2016-09-20 161 views
1

我看到了很多示例,並嘗試了很多解決方案,但都沒有成功! 我想把我的項目與Apache的Ubuntu服務器。從URL刪除index.php,Laravel 5.2

一切其確定當我這樣做:

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

但我想:

"/MYEXAMPLE/public/dashboard" 

而且有問題!

「在此服務器上未找到請求的URL/MYEXAMPLE/public/dashboard。」

Apache服務器具有德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的服務器,但該網址的不工作,因爲我需要的index.php

其他的例子:如果我訪問

/MYEXAMPLE/public/ 

OR

/MYEXAMPLE/public/index.php 

它根據需要前往主頁。問題是他在什麼時候想改變到其他頁面!

任何解決問題的建議?爲什麼一切正常,運行wamp,當我嘗試使用Ubuntu服務器時,我需要URL處的index.php?

在此先感謝

+0

Laravel的文檔根目錄應該是公共文件夾。閱讀安裝說明。 – Blake

+2

[無法從laravel url中刪除index.php的可能重複?在Ubuntu的14.04](http://stackoverflow.com/questions/36001521/unable-to-remove-index-php-from-laravel-url-in-ubuntu-14-04) –

回答

3

您需要point web server to public directory和正常使用的URL像/dashboard而不是/public/index.php/dashboard

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

此外,您還可以使用此working Apache virtual host configuration for Laravel

<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>