【发布时间】:2014-04-22 10:29:45
【问题描述】:
我要疯了!我正在尝试学习 Laravel,但漂亮的 URL 是行不通的。
我已经从我的 apache 配置文件中启用了 mod_rewrite,我在我的用户配置文件中将 AllowOverride 设置为 All,并且我在 Laravel 安装的 public 文件夹中的 .htaccess 文件中有以下内容:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [L]
我输入http://localhost/~user/lara/public/index.php/users 它可以工作,但是使用http://localhost/~user/lara/public/users 我得到404 Not Found 错误
The requested URL /Users/user/Sites/lara/public/index.php/users was not found on this server.
您可以看到重定向工作正常,因为 public/users 已变成 public/index.php/users 但它说未找到,即使当我手动输入 public/index.php/users 时它也会显示输出。
我已经阅读了关于 SO 的所有相关问题,但没有一个对我有用!
【问题讨论】:
-
这可能只是您的问题中的拼写错误,但适合您的 URL 不在
public目录中:/~user/lara/index.php/users而不是/~user/lara/public/index.php/users,这是您的重写器会做的对于/~user/lara/public/usersURL。 -
确实是错字,刚刚更正了
-
哦。哦,好吧,我们对快速修复的希望和梦想到此为止!
-
绝对 :( 我真的要疯了
-
这可能是因为
~user正在使用 mod_userdir (或类似的东西),因此重写规则实际上并没有正确重写(即使看起来是这样)。尝试在RewriteBase /~user/lara/public/添加一个 RewriteBase 我知道这不是一个优雅的修复,但如果它有效,它就有效,对吧?
标签: laravel pretty-urls