2017-09-23 48 views
0

我在Linux Mint中使用Laravel 5.5.12。我使用LAMP堆棧。我想從URL中刪除index.php。我的mod_rewrite apache模塊已啓用。從Laravel的URL中刪除index.php

我的.htaccess文件位於public文件夾中,它包含以下代碼。

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

    Options +FollowSymLinks 

    # Redirect Trailing Slashes If Not A Folder... 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_URI} (.+)/$ 
    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}] 
</IfModule> 

我改名的Laravel根文件夾中的index.php的server.php和複製從/ public目錄到Laravel根目錄下的.htaccess文件。但它不起作用。

我把下面的代碼在.htaccess文件

<IfModule mod_rewrite.c> 

    # Turn Off mod_dir Redirect For Existing Directories 
    DirectorySlash Off 

    # Rewrite For Public Folder 
    RewriteEngine on 
    RewriteRule ^(.*)$ public/$1 [L] 

</IfModule> 

但這不工作。

任何人都可以在這方面幫助我嗎?

+2

「我將Laravel根文件夾中的server.php重命名爲index.php,並將.htaccess文件從/ public目錄複製到Laravel根文件夾。」讓我擔心。你爲什麼不只是配置你的Web服務器指向公用文件夾? – sisve

回答

1

將您已更改的任何內容重置爲默認值。

在你的apache虛擬主機配置中,確保你有DocumentRoot正確的(它會像/ var/www/html/laravelproject/public一樣)。

您不應該在公用文件夾中對.htaccess文件進行任何更改,因爲這會處理重寫url以刪除index.php。然而,在某些環境下,我不得不

RewriteBase /laravelproject 

添加到htaccess的公共文件夾中。