繁体   English   中英

从 Laravel 的 URL 中删除 index.php

[英]Remove index.php from URL of Laravel

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

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

我将以下代码放在.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>

但这不起作用。

任何人都可以在这方面帮助我吗?

将您更改的任何内容重置为默认值。

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

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

RewriteBase /laravelproject

到公用文件夹中的 .htaccess。

我在这里找到了答案:

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

总而言之,我将以下内容添加到 .htaccess 文件中,直接位于现有 index.php 条目的下方:

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

Go 到httpd.conf文件,搜索行DocumentRoot并将其更改为您的index.php所在的位置。 例如:

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

暂无
暂无

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

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