Laravel 4 .htaccess 不重写 URL

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16912134/
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:52:39  来源:igfitidea点击:

Laravel 4 .htaccess Not Rewriting URLs

.htaccesslaravellaravel-4

提问by Dalton Gore

So I've just upgraded to Laravel 4, and I'm setting things up on a new server. The default /route works fine, but every other route returns a 404 error. When trying index.php/route, I get the requested data, so that means that .htaccess isn't working.

所以我刚刚升级到 Laravel 4,我正在一台新服务器上进行设置。默认/路由工作正常,但其他所有路由都会返回 404 错误。尝试时index.php/route,我得到了请求的数据,所以这意味着 .htaccess 不起作用。

Yes, AllowOverride is set to ALL.
Yes, I enabled the mod_rewrite module.

是的,AllowOverride is set to ALL
是的,我enabled the mod_rewrite module

I have tried the following 3 .htaccess combinations:

我尝试了以下 3 种 .htaccess 组合:

<IfModule mod_rewrite.c>
    Options -MultiViews
    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

and:

和:

<IfModule mod_rewrite.c>
   RewriteEngine on

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

   RewriteRule ^(.*)$ index.php/ [L]
</IfModule>

and:

和:

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ http://%{HTTP_HOST}/ [R=301,L]

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

And, after a server restart, and so on, none of them are working, and I'm still returning a 404 error.

而且,在服务器重新启动等之后,它们都不起作用,我仍然返回 404 错误。

Note: I am using several domains with the same laravel install, so my public folders are public/site1, public/site2, public/site3. However, I am routing the public paths to these folders, so I'm not sure that would be the problem.

注意:我使用多个域进行相同的 Laravel 安装,所以我的公共文件夹是public/site1, public/site2, public/site3. 但是,我将公共路径路由到这些文件夹,所以我不确定这会是问题所在。

Any thoughts?

有什么想法吗?

回答by Dalton Gore

I forgot to edit the vhosts in httpd.conf. Derp, derp. Added:

我忘了在 httpd.conf 中编辑 vhosts。德普,德普。添加:

<Directory "/var/www/public/site1">
    AllowOverride All
</Directory>

to each of the site's vhost files, and it worked beautifully. Derp derp.

到每个站点的 vhost 文件,它运行得很好。德普德普。