Laravel 快速入门指南路线不起作用

2022-01-08 00:00:00 php laravel laravel-4

好的,我是 Laravel 的新手,所以直接阅读文档开始.文档中存在大量漏洞,因此需要花费大量精力和谷歌搜索来填补空白,以便设置 Laravel.我现在已经设置好它并进入快速入门指南中的下一步.我创建了我的路线

Ok I'm new to Laravel so went straight to the documentation to get started. There are massive holes in the documentation so it took a lot of effort and googling to fill the gaps in order to get Laravel set-up. I now have it set up and moved on to the next step in the quick start guide.I created my route

Route::get('users', function()
{
     return 'Users!';
});

现在它说:

Now, if you hit the /users route in your web browser, you should see Users!

所以我打了起来:

http://localhost/laravel/users 

但是得到一个 404?我试过了

but get a 404? I tried

http://localhost/laravel/public/users 

但仍然是 404?我按照这封信的快速入门指南中的步骤操作,我错过了什么?

but still a 404? I followed the steps on the quick start guide to the letter, what am I missing?

推荐答案

看起来你的 Laravel 应用可以通过 Apache HTTP 别名访问,因为你的 URL 看起来像:http://localhost/laravel/.如果是这种情况并假设 http://localhost/laravel 指向您的公共目录,请按照以下步骤操作:

Seems like your Laravel app is accesible via an Apache HTTP alias, because your URL looks like: http://localhost/laravel/. If this is the case and assuming that http://localhost/laravel is pointing to your public directory, then follow these steps:

  1. 尝试使用 /index.php/ 导航到您预期的路线,在您的情况下:http://localhost/laravel/index.php/users.如果它有效(没有 404),那么您的问题在于 Apache HTTP 的重写模块配置,您应该按照以下步骤操作.
  2. 编辑文件public/.htaccess.
  3. RewriteEngine On 行下添加 RewriteBase/laravel/.
  4. 尝试导航到现有路线.
  1. Try to navigate to your expected route prepend it with /index.php/, in your case: http://localhost/laravel/index.php/users. If it works (no 404) then you problem is with the Rewrite Module configuration of Apache HTTP, you should follow the next steps.
  2. Edit the file public/.htaccess.
  3. Under the line RewriteEngine On add RewriteBase /laravel/.
  4. Try to navigate to an existing route.

基本上,如果您的应用程序驻留在别名或虚拟目录中(例如 http://localhost/alias),您应该在重写规则中添加一个条目来重写 基本目录 带有 别名.

Basically, if you app resides in a alias or virtual directory (say http://localhost/alias) you should add an entry in your rewrite rule to rewrite the base directory with alias.

相关文章