2016-11-29 96 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>