从 xampp 移动到 apache 2.4.7 后,Laravel 路由返回 404。mod_rewrite 或 htacess 或缺少 apache 设置?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21274344/
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 routes returning 404 after move from xampp to apache 2.4.7. mod_rewrite or htacess or missing apache setting?
提问by Sen Heng
a simple 'test' route keeps returning a 404.
一个简单的“测试”路线不断返回 404。
Route::get('test', function() {
return View::make('test');
});
The route doesn't work whether it's localhost/test, or vhost.dev/test or even when using our sub.domain.com/test with the DNS pointing to that particular laptop.
无论是 localhost/test 还是 vhost.dev/test,甚至在使用我们的 sub.domain.com/test 和 DNS 指向该特定笔记本电脑时,该路由都不起作用。
We were using XAMPP but switched to apache after learning that xampp was not suitable for a production environment. So I installed apache 2.4.7, php and the various sqlsrv mods on one of our win7 laptops. After moving to Apache, all routes have stopped working even with the same directory structure.
我们使用 XAMPP,但在得知 xampp 不适合生产环境后切换到 apache。所以我在我们的一台 win7 笔记本电脑上安装了 apache 2.4.7、php 和各种 sqlsrv mods。迁移到 Apache 后,即使使用相同的目录结构,所有路由都已停止工作。
I've also tried moving all files in /public into /htdocs and the rest of the app into a laravel folder in the root apache2.4 folder.
我还尝试将 /public 中的所有文件移动到 /htdocs 中,并将应用程序的其余部分移动到根 apache2.4 文件夹中的 laravel 文件夹中。
I'm tested if mod_rewrite is enabled using this code on SO. This is the response so I suppose it is working?
我在 SO 上使用此代码测试是否启用了 mod_rewrite 。这是响应,所以我想它正在工作?
Apache/2.4.7 (Win32) PHP/5.4.24
mod_rewrite available
Apache/2.4.7 (Win32) PHP/5.4.24
mod_rewrite 可用
htaccess
访问
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/ [L]
</IfModule>
回答by Sen Heng
This was answered on the Laravel forums.
The problem was because AllowOverride
was set to None
in Apache. Changing that to All
solved all the routing problems.
问题是因为在 ApacheAllowOverride
中设置为None
。改变它以All
解决所有路由问题。
Here is the example virtual host configuration from the post:
这是帖子中的示例虚拟主机配置:
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName yoursite.com
ServerAlias www.yoursite.com
DocumentRoot "/var/www/yoursite.com/public"
<Directory /var/www/yoursite.com/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
回答by timminss
Is mod_rewrite enabled on the new server?
新服务器上是否启用了 mod_rewrite?
a2enmod rewrite
回答by NikolaiDante
You should try http://localhost/laravel/public/index.php/test
and that should work. Also you should consider using nginx as server, that's more flexible than apache.
你应该尝试http://localhost/laravel/public/index.php/test
,这应该有效。您还应该考虑使用 nginx 作为服务器,这比 apache 更灵活。
In above http link, laravel is your laravel directory
在上面的 http 链接中,laravel 是你的 laravel 目录