2016-11-29 90 views
1

我的網址是這樣的:http://31.220.56.75/mysystem/public/index.php/login如何刪除url中的index.php? (laravel 5.3,PHP 7)

我想刪除的index.php,是這樣的:http://31.220.56.75/mysystem/public/login

我的.htaccess:

<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}] 
</IfModule> 

我嘗試一些教程谷歌。但我沒有找到解決辦法

更新

我嘗試更新的.htaccess這樣的:

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

它不工作

+1

確保啓用了mod_rewrite。 'a2enmod rewrite',然後重新加載apache服務。 –

+0

@Laurent Meganck,我曾經運行它。但是,它不工作 –

+0

Laravel的默認HTACCESS文件應該已經工作。您有任何機會錯誤地設置您的虛擬主機? – Ronald

回答

0

試試這個

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

這不起作用 –

0

默認.htaccess公用文件夾守ld工作得很好。檢查:original .htaccess

+1

也許他的虛擬主機配置沒有指向公用文件夾。可能是問題? –

+0

我現在正在編輯答案。 –

+0

但即使它不是。它應該工作。它不是它自己的.htaccess –

0

請按照下面的.htaccess文件,希望這將工作。

如果您面臨$ _GET變量的問題,也就是說,如果您的兩個URL index.php和沒有index.php正在工作,但$ _GET變量發現不工作,那麼下面的.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] 

</IfModule>