Laravel Route 不适用于 Wamp

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15607132/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 07:38:27  来源:igfitidea点击:

Laravel Route not working with Wamp

phpmod-rewriterouteswamplaravel

提问by spm

As the title states, I cannot get my site to redirect. I've made several attempts and am about to lose it.

正如标题所述,我无法让我的网站重定向。我已经进行了几次尝试,但即将失败。

My .htaccess file is as follows:

我的 .htaccess 文件如下:

Options +FollowSymLinks
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . index.php [L]

I have this file placed in the www/Laravel/public folder as well as www directory

我将此文件放在 www/Laravel/public 文件夹以及 www 目录中

  • mod_rewrite is enabled
  • AllowOverride is set to All
  • mod_rewrite 已启用
  • AllowOverride 设置为 All

My host file is as follows

我的主机文件如下

127.0.0.1       localhost

Here is the code for route contained in routes.php

这是routes.php中包含的路由代码

Route::get('authors', array('uses'=>'authors@index'));

I have a controller named authors.php, here is the code

我有一个名为authors.php的控制器,这是代码

class Authors_Controller extends Base_Controller {
public $restful = true;
public function get_index () {      
    return View::make('authors.index');}
}

I am using Windows 7 Ultimate. I'm about to blow my brains out. Please help me, I suck.

我正在使用 Windows 7 Ultimate。我要炸了我的脑袋。请帮帮我,我很烂。

回答by Thomas Venturini

If your laravel project is located in c:\wamp\laravel\ then you should be able to call http://localhost/laravel/publicand see the default laravel welcome page or your own.

如果您的 Laravel 项目位于 c:\wamp\laravel\,那么您应该能够调用 http://localhost/laravel/public并查看默认的 Laravel 欢迎页面或您自己的。

If thats the case, you have to check two thins:

如果是这种情况,您必须检查两个细项:

  1. Open your /app/config/app.php file and check that the value of url directs to your project. 'url'=>'http://localhost/laravel/
  2. Then open your .htaccess file and add the RewriteBase rule under the RewriteEngine OnLine RewriteBase /laravel/public/
  1. 打开您的 /app/config/app.php 文件并检查 url 的值是否指向您的项目。 'url'=>'http://localhost/laravel/
  2. 然后打开你的 .htaccess 文件并在RewriteEngine OnLine 下添加 RewriteBase 规则RewriteBase /laravel/public/

Hope that helps! :)

希望有帮助!:)

回答by JCharette

I had the same problem. I used the solution above and it worked.

我有同样的问题。我使用了上面的解决方案并且它起作用了。

Apache rewrite_module must be enable in wamp as well.

Apache rewrite_module 也必须在 wamp 中启用。

回答by Kylie

You need to setup a virtual host pointing to your public directory... in httpd.conf file.

您需要在 httpd.conf 文件中设置一个指向您的公共目录的虚拟主机。

Which can be found under the Apache menu...

可以在 Apache 菜单下找到...

Like so...

像这样...

<VirtualHost *:80>
DocumentRoot c:\wamp\www\laravel\public
ServerName testing.com
</VirtualHost>

And your hosts file will reflect the url you choose...in this case...testing.com

并且您的主机文件将反映您选择的网址...在这种情况下...testing.com

127.0.0.1      testing.com

回答by Peter Gathee

Checking rewrite_module

检查 rewrite_module

Go to

  • wamp icon
  • Apache
  • Apache modules
  • check rewrite_module
  • wamp 图标
  • 阿帕奇
  • Apache 模块
  • 查看 rewrite_module

And cheers , there you are after some headache

干杯,你在头痛

回答by mahmoud ibrahim

Apache rewrite_modulemust be enabled in WAMP as well. It works with my wampserver.

Apache 也rewrite_module必须在 WAMP 中启用。它适用于我的 wampserver。

回答by Md. Shahinur Alam

Actually it has a pretty easy solution. All you have to do just check the rewrite module in apache. Check the steps in image laravel problem with wamp server solution

其实它有一个非常简单的解决方案。您只需检查 apache 中的重写模块即可。用wamp服务器解决方案检查图像laravel问题中的步骤

回答by Joy Hanawa

Create an index.php file in the root.

在根目录中创建一个 index.php 文件。

<?php
header("refresh: 0; http://localhost/appnamehere/public");
?>

If you have multiple sites under one domain, you may not be able to change your public webroot.

如果您在一个域下有多个站点,您可能无法更改您的公共 webroot。

I had all the correct settings, and the right .htaccess files in the right place, but it would not redirect. This fixed it for me.

我有所有正确的设置,正确的地方有正确的 .htaccess 文件,但它不会重定向。这为我修好了。

This article was helpful in getting the wampserver/wampmanager links working. Project Links do not work on Wamp Server

本文有助于使 wampserver/wampmanager 链接正常工作。 项目链接在 Wamp 服务器上不起作用

Post Script:

发布脚本:

If you add to the virtual host file at: E:\wamp\bin\apache\apache2.4.23\conf\extra\httpd-vhosts.conf and you create a virtual host that points to the public directory like this:

如果添加到虚拟主机文件: E:\wamp\bin\apache\apache2.4.23\conf\extra\httpd-vhosts.conf 并创建一个指向公共目录的虚拟主机,如下所示:

<VirtualHost *:80>
    ServerName Blog
    ServerAlias Blog
    DocumentRoot E:/wamp/www/Blog/public
    <Directory  "E:/wamp/www/Blog/public/">
        Options +Indexes +Includes +FollowSymLinks +MultiViews
       AllowOverride All
        Require local
    </Directory>
</VirtualHost>
#

and you add to C:\Windows\System32\drivers\etc\hosts

然后添加到 C:\Windows\System32\drivers\etc\hosts

# localhost name resolution is handled within DNS itself.
    127.0.0.1       localhost
    ::1             localhost
    127.0.0.1       Blog
    ::1             Blog

You do not need the index.php file I suggested. That file works if you are NOT creating a virtual host, both are not needed. It's one or the other (although it does no harm to have it).

您不需要我建议的 index.php 文件。如果您不创建虚拟主机,则该文件有效,两者都不需要。它是一个或另一个(尽管拥有它没有坏处)。

回答by Alexey Mezenin

They only right way to do this is to point web server to publicdirectory. For example, if you've installed Laravel in C:/xampp/htdocs/directory, you need to use these settings:

他们唯一正确的方法是将 Web 服务器指向public目录。例如,如果您在C:/xampp/htdocs/目录中安装了 Laravel ,则需要使用以下设置:

DocumentRoot "C:/xampp/htdocs/public"
<Directory "C:/xampp/htdocs/public">

Never edit .htaccessinside public folder. If you did this, you need to get original file back. Restart Apache after you make these changes.

切勿.htaccess在公用文件夹内编辑。如果这样做,则需要取回原始文件。进行这些更改后重新启动 Apache。