从Laravel的网址中删除index.php [英] Remove index.php from URL of Laravel

查看:99
本文介绍了从Laravel的网址中删除index.php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Linux Mint中使用Laravel 5.5.12,正在使用LAMP堆栈.我想从URL中删除index.php.我的mod_rewrite apache模块已启用.

I am using Laravel 5.5.12 in Linux Mint.I am using LAMP stack. I would like to remove index.php from URL. My mod_rewrite apache module enabled.

我的.htaccess文件位于public文件夹中,它包含以下代码.

My .htaccess file located in public folder and it contains following code.

<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根文件夹中的server.php重命名为index.php,并将.htaccess文件从/public目录复制到Laravel根文件夹.但这是行不通的.

I renamed the server.php in the Laravel root folder to index.php and copy the .htaccess file from /public directory to Laravel root folder. But it is not working.

我在.htaccess文件中的代码下面放置了

I placed below code in .htaccess file

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

但这不起作用.

在这方面有人可以帮助我吗?

Could anyone help me in this regard ?

推荐答案

将已更改的所有内容重置为默认值.

Reset anything you have changed back to the default.

在apache虚拟主机配置中,确保您具有正确的DocumentRoot(类似于/var/www/html/laravelproject/public).

In your apache virtual host configuration, ensure you have the DocumentRoot correct (it will be something like /var/www/html/laravelproject/public).

您不需要对公共文件夹中的.htaccess文件进行任何更改,因为这可以重写url以删除index.php.但是,在某些环境中,我不得不添加

You should not need to make any changes to the .htaccess file in the public folder as this handles rewriting the url to remove index.php. However, in some environments, I have had to add

RewriteBase /laravelproject

到公用文件夹中的.htaccess.

to the .htaccess in the public folder.

这篇关于从Laravel的网址中删除index.php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆