【问题标题】:routing with htaccess and laravel使用 htaccess 和 laravel 进行路由
【发布时间】:2013-12-08 11:18:06
【问题描述】:

您好,我正在使用以下 htaccess

<IfModule mod_rewrite.c>
Options +FollowSymLinks
Options -MultiViews
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

用于做 laravel 路由。

当我浏览 example localdevurl/public/users 时,我收到以下错误 (404)

找不到

在此服务器上找不到请求的 URL /Users/username/Sites/sitefolder/public/index.php/user。

但正如您所见,它在错误中显示了 index.php。当我将 index.php 放入我的网址时,它确实有效。我已经打开了我的 apache 配置中的所有内容。

httpd.conf

谁能看到我在这里做错了什么?

【问题讨论】:

标签: php apache .htaccess laravel-4


【解决方案1】:

在您的 .htaccess 文件中,您在 index.php 部分之后传递请求,而不是让 laravel 路由系统处理它,这是:

RewriteRule ^(.*)$ index.php/$1 [L]

应该是原来的.htaccess

RewriteRule ^ index.php [L]

我在 index.php 部分遇到了同样的问题,这就是我解决的方法:启用 userdir 模块 时出现问题,这似乎是基于 URL 的情况的错误信息。

可能的解决方案:

  • 在 webserver 文件夹中创建指向用户 web 目录的 public laravel 项目文件夹的符号链接。例如:# ln -s ~/public_html/mylaravel4/site/public/ /var/www/mycoolsite 然后就可以访问http://localhost/mycoolsite
  • 将 RewriteCond 和 RewriteRule 行替换为:FallbackResource /index.php

【讨论】:

    【解决方案2】:

    确保您将特定虚拟主机的 AllowOverride 设置为 All 而不是 None,并在 httpd.conf 中设置 Order allow、deny 而不是 Order deny、allow。

        AllowOverride all
        Order allow, deny
    

    【讨论】:

      猜你喜欢
      • 2016-05-01
      • 2018-11-16
      • 2016-01-09
      • 2016-02-10
      • 2019-03-05
      • 2015-04-23
      • 1970-01-01
      • 1970-01-01
      • 2016-03-04
      相关资源
      最近更新 更多