Laravel 4 虚拟主机和 mod 重写设置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19802286/
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
Laravel 4 Virtual Host and mod rewrite setup
提问by Zubzob
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 7machine and WAMP.
我已经尝试了几个小时来安装 Laravel 4 并使虚拟主机和路由正常工作,但到目前为止我一直很不走运。我提到我在Windows 7机器和WAMP上这样做。
I'll describe what I've already done:
我将描述我已经做过的事情:
I've enabled rewrite_module.
我已启用 rewrite_module。
Updated httpd-vhosts.conf with the following:
使用以下内容更新了 httpd-vhosts.conf:
<VirtualHost *:80>
DocumentRoot "c:/wamp/www/laravel/public"
ServerName laravel.dev
ServerAlias www.laravel.dev
</VirtualHost>
Next, I've set up the etc/hosts
:
接下来,我设置了etc/hosts
:
127.0.0.1 localhost
127.0.0.1 laravel.dev
Also, the following lines are uncommented both in wamp/../conf/httpd.conf
and in wamp/.../conf/original/httpd.conf
:
此外,以下行在 inwamp/../conf/httpd.conf
和 in 中均未注释wamp/.../conf/original/httpd.conf
:
LoadModule vhost_alias_module modules/mod_vhost_alias.so
Include conf/extra/httpd-vhosts.conf
The content of my .htaccess
is the following:
我的内容.htaccess
如下:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteRule ^(.*)$ public/ [L]
</IfModule>
Yet,when I go to http://laravel.devI get an Internal Server Error - The server encountered an internal error or misconfiguration and was unable to complete your request..
然而,当我去http://laravel.dev我得到一个内部服务器错误-服务器遇到一个内部错误或配置错误,无法完成您的请求。.
If i remove the .htaccess
file from the publicfolder, then I'll see the Laravel "You have arrived" message. If then, i create a route like this (within the app\routes.php):
如果我.htaccess
从公共文件夹中删除文件,那么我会看到 Laravel “您已到达”消息。如果那样的话,我会创建一个这样的路线(在app\routes.php 中):
Route::get('/newroute', function()
{
return View::make('hello');
});
and then go to http://laravel.dev/newrouteI'll end up with a 404 Not Found - The requested URL /newroute was not found on this server.
然后转到http://laravel.dev/newroute我最终会得到404 Not Found - 在此服务器上找不到请求的 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.
我很困惑,不知道如何才能度过难关。我提到(虽然我认为很清楚)我composer install
在克隆项目模板、安装依赖项后运行了一个。
采纳答案by Jon Lin
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 文件在您的/public/
文件夹中,那么这就是您收到 500 内部服务器错误的原因。该 htaccess 文件是为文件夹所在的/public/
文件夹制作的。但由于您的公用文件夹是文档根目录,因此您不需要它。
The htaccess file inthe /public/
folder should look like this:
该htaccess文件中的/public/
文件夹应该是这样的:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
(for WAMP).
(对于 WAMP)。
回答by hayhorse
Try turning on AllowOverride All on the directory by changing your VirtualHost to:
尝试通过将 VirtualHost 更改为以下内容来打开目录上的 AllowOverride All:
<VirtualHost *:80>
DocumentRoot "c:/wamp/www/laravel/public"
ServerName laravel.dev
ServerAlias www.laravel.dev
<Directory "c:/wamp/www/laravel/public">
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
回答by Amit Garg
I have gone through the same issue and followed the all the treatments given above but virtual host can not be set.
我遇到了同样的问题并遵循了上面给出的所有处理方法,但无法设置虚拟主机。
When I inspected file http.conf
then I found that inclusion of file httpd-vhosts.conf
was commented as given below. Make sure to include httpd-vhosts.conf
in httpd.conf.
当我检查文件时,http.conf
我发现包含文件的httpd-vhosts.conf
注释如下所示。确保包含httpd-vhosts.conf
在 httpd.conf 中。
#Include conf/extra/httpd-vhosts.conf
#Include conf/extra/httpd-vhosts.conf
I have removed the #
comment. Restarted the wamp and it was working.
我已经删除了#
评论。重新启动 wamp,它正在工作。
Include conf/extra/httpd-vhosts.conf
Include conf/extra/httpd-vhosts.conf