【问题标题】:Laravel URL::route and index.phpLaravel URL::route 和 index.php
【发布时间】:2014-01-25 19:52:17
【问题描述】:

我的网站使用 Laravel PHP 框架。在我的导航中,我有这样的 li 元素。

<li class="{{ URL::current() == URL::route("mainpage") ? "active" : "" }}"><a href="{{ URL::route("mainpage") }}">Home</a></li>
<li class="{{ URL::current() == URL::route("portfolio") ? "active" : "" }}"><a href="{{ URL::route("portfolio") }}">Portfolio</a></li>

我使用URL::route 在我的routes.php 中获取到命名路由的链接,并使用current 方法检查页面是否处于活动状态,并在这种情况下向元素添加active 类。

如果用户的路径中没有 index.php,这一切都可以完美运行。如果那是在 URL 中,那么链接将看起来像 domain.com/index.php/portfolio 这不好。

如何使链接不包含 index.php?

【问题讨论】:

  • 你在设置中使用的是什么版本的 Laravel?

标签: php laravel


【解决方案1】:

好吧,您可以确保用户始终在 URL 中没有 index.php 的情况下进入网站。这可以通过永久重定向来完成,因此您需要修改 .htaccess 并添加永久重定向。

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

【讨论】:

  • 感谢您的评论。我正在使用 IIS,所以这不起作用。我不能让链接正确生成吗?
【解决方案2】:

检查您的 /app/config/app.php 文件。如果包含

'index' => 'index.php'

删除 index.php(将值留空)。这有帮助吗?

【讨论】:

  • 感谢您的回答。我的配置文件没有那个条目。
  • 该选项在较低版本的 laravel 4 中
猜你喜欢
  • 2015-05-19
  • 2014-12-19
  • 2013-06-09
  • 2019-02-26
  • 2020-01-27
  • 2017-01-28
  • 2018-03-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多