【问题标题】:Remove index.php from url Laravel 5从网址 Laravel 5 中删除 index.php
【发布时间】:2018-04-05 10:04:12
【问题描述】:

URL 在我的应用程序中运行良好。我的意思是它们是漂亮的 URL。喜欢 http://www.example.com/ 但是,当您使用 index.php (如 http://www.example.com/index.php)访问页面时,它也可以工作,这是我不想要的,因为它在站点地图中为一个页面显示了两个链接。一页没有index.php,另一页有index.php。站点地图的演示在这里https://www.xml-sitemaps.com/details-eln.6762418.html

这里是 .htaccess

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

【问题讨论】:

  • 从站点地图中删除您不想要的似乎是最简单的解决方案。
  • 正确。 bt 我想在应用程序端修复它。

标签: php apache .htaccess laravel-5 laravel-routing


【解决方案1】:

输入以下代码:

RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,7}\s/(.*)index\.php\sHTTP.*$
RewriteRule ^ /%1 [R=301,L]

【讨论】:

  • 当我实现上述代码时,index.php 的问题已解决,但所有链接都已损坏。有什么想法吗?
  • 它在根目录中。
  • 如果我在本地机器上运行localhost/myproject/index.php,它将带我回到localhost/xampp。这样对吗?我的意思是它应该带我回到localhost/myproject。你说什么?
  • 它不适用于其他链接。你能在你的答案中粘贴 .htaccess 文件的完整代码吗?
  • NGinx 呢?
猜你喜欢
  • 2019-09-14
  • 1970-01-01
  • 1970-01-01
  • 2015-10-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-27
  • 2017-01-28
相关资源
最近更新 更多