Laravel 4虚拟主机和mod-rewrite设置虚拟主机、Laravel、rewrite、mod

2023-09-02 00:33:58 作者:别忘了呼吸就好

我一直在尝试了几个小时来安装Laravel 4,使虚拟主机和路由工作,但到目前为止,我一直不走运。我提的是,我是一个 Windows 7中机上这样做的, WAMP

I've been trying for a few hours to install Laravel 4 and make the Virtual Hosts and Routing work but so far I've been unlucky. I'm mentioning that I'm doing this on a Windows 7 machine and WAMP.

我来描述一下我已经做了:

I'll describe what I've already done:

我已经启用rewrite_module。

I've enabled rewrite_module.

更新的httpd-vhosts.conf与以下内容:

Updated httpd-vhosts.conf with the following:

<VirtualHost *:80>
    DocumentRoot "c:/wamp/www/laravel/public"
    ServerName laravel.dev
    ServerAlias www.laravel.dev
</VirtualHost>

接下来,我已经设置了 etc / hosts中

127.0.0.1       localhost
127.0.0.1       laravel.dev

此外,下面的线是未加注释无论在瓦帕/../的conf / httpd.conf文件瓦帕/.../的conf /original/httpd.conf

LoadModule vhost_alias_module modules/mod_vhost_alias.so

Include conf/extra/httpd-vhosts.conf

的内容我的的.htaccess 如下:

<IfModule mod_rewrite.c>
    Options -MultiViews
    RewriteEngine On

    RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

然而,当我去 http://laravel.dev 我得到的内部服务器错误 - 。服务器遇到一个内部错误或配置错误,无法完成您的请求的

如果我删除了的公开的文件夹,然后我就看到了Laravel您已到达消息的.htaccess 文件。如果当时,我创建一个这样的途径(内部的应用程序 routes.php文件的):

If i remove the .htaccess file from the public folder, then I'll see the Laravel "You have arrived" message. If then, i create a route like this (within the approutes.php):

Route::get('/newroute', function()
{
    return View::make('hello');
});

,然后转至 http://laravel.dev/newroute 我结束了一个 404未找​​到 - 所请求的URL / newroute在此服务器上找到。的

我是认真迷茫,不知道我该如何突破这个。我提到(虽然我认为这是明显的),我跑了作曲家安装克隆后的项目模板,安装的依赖关系。

I am seriously confused and have no idea how I can get past this. I mention (although i think it's clear) that I ran a composer install after cloning the project template, installing the dependencies.

推荐答案

如果你发布的htaccess文件是在 /公/ 文件夹,那么这就是为什么你'再得到一个500内部服务器错误。这htaccess文件是为使 /公/ 文件夹中的在的文件夹。但由于你的公共文件夹是文档根目录,你不需要它。

If the htaccess file that you posted was in your /public/ folder, then that's why you're getting a 500 internal server error. That htaccess file was made for the folder that the /public/ folder is in. But since your public folder is the document root, you don't need it.

在htaccess文件的在的的 /公/ 文件夹应该是这样的:

The htaccess file in the /public/ folder should look like this:

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

(对于WAMP)。

(for WAMP).