简体   繁体   English

从 Laravel 的 URL 中删除 index.php

[英]Remove index.php from URL of Laravel

I am using Laravel 5.5.12 in Linux Mint.I am using LAMP stack.我在 Linux Mint 中使用 Laravel 5.5.12。我正在使用 LAMP 堆栈。 I would like to remove index.php from URL. My mod_rewrite apache module enabled.我想从 URL 中删除index.php 。我的mod_rewrite apache 模块已启用。

My .htaccess file located in public folder and it contains following code.我的.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>

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.我将 Laravel 根文件夹中的 server.php 重命名为 index.php 并将 .htaccess 文件从 /public 目录复制到 Laravel 根文件夹。 But it is not working.但它不起作用。

I placed below code in .htaccess file我将以下代码放在.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>

But this not working.但这不起作用。

Could anyone help me in this regard?任何人都可以在这方面帮助我吗?

Reset anything you have changed back to the default.将您更改的任何内容重置为默认值。

In your apache virtual host configuration, ensure you have the DocumentRoot correct (it will be something like /var/www/html/laravelproject/public).在您的 apache 虚拟主机配置中,确保您的 DocumentRoot 正确(类似于 /var/www/html/laravelproject/public)。

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.您不需要对公共文件夹中的 .htaccess 文件进行任何更改,因为这会处理重写 url 以删除 index.php。 However, in some environments, I have had to add但是,在某些环境中,我不得不添加

RewriteBase /laravelproject

to the .htaccess in the public folder.到公用文件夹中的 .htaccess。

I found the answer here:我在这里找到了答案:

https://ma.ttias.be/remove-index-php-from-the-url-in-laravel/ https://ma.ttias.be/remove-index-php-from-the-url-in-laravel/

To summarise, I added the following to the .htaccess file, directly below the existing index.php entry:总而言之,我将以下内容添加到 .htaccess 文件中,直接位于现有 index.php 条目的下方:

RewriteRule ^index.php/(.+) /$1 [R=301,L]

Go to httpd.conf file, search for the line DocumentRoot and change it to where ever your index.php is. Go 到httpd.conf文件,搜索行DocumentRoot并将其更改为您的index.php所在的位置。 For example:例如:

DocumentRoot "C:/xampp/htdocs/myappfolder/public"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM