Laravel 重定向到一个路由,但随后 apache 给出了 404 错误

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

Laravel redirects to a route but then apache gives 404 error

phpapache.htaccessredirectlaravel

提问by Proen?a

I have a site that is working on the same server in a different url (staging), but now I've deployed the site and the base url ("/") is redirected to the login url (so laravel is sort of working), but then I get a 404 error from apache.

我有一个站点在不同的 url(暂存)中在同一台服务器上工作,但现在我已经部署了该站点,并且基本 url(“/”)被重定向到登录 url(所以 laravel 有点工作) ,但随后我收到来自 apache 的 404 错误。

If I use sub.domain.com/index.php/route, it works, but if I use sub.domain.com/route redirects to the login route and gives a 404 error.

如果我使用 sub.domain.com/index.php/route,它可以工作,但如果我使用 sub.domain.com/route 重定向到登录路由并给出 404 错误。

I also changed the routes.php to return the login view in the route "/" and it show the login form correctly.

我还更改了 routes.php 以在路由“/”中返回登录视图,并正确显示登录表单。

回答by Proen?a

After adding

添加后

AllowOverride All

to the vhost configuration, got it working. Probably the default configuration wasn't allowing the redirects?

到 vhost 配置,让它工作。可能默认配置不允许重定向?

Here's my final (and working) vhost configuration:

这是我的最终(和工作)虚拟主机配置:

DocumentRoot /var/www/sitefolder/public
 ServerName site.domain.com
 <Directory /var/www/sitefolder/public>
  AllowOverride All
  allow from all
  Options +Indexes
</Directory>

回答by Mithredate

The problem might come from a module in your Apache server called rewrite module. in windows you can just uncomment this line from your httpd.conf

问题可能来自 Apache 服务器中名为 rewrite 模块的模块。在 Windows 中,您可以从 httpd.conf 中取消注释此行

#LoadModule rewrite_module modules/mod_rewrite.so

#LoadModule rewrite_module modules/mod_rewrite.so

I'm running Ubuntu 14.04 and enabled it using

我正在运行 Ubuntu 14.04 并使用

sudo a2enmod rewrite

sudo a2enmod rewrite

Try these with an Apache restart. It might work for you as well.

在 Apache 重新启动时尝试这些。它也可能对你有用。

回答by ch271828n

For VirtualHost

为了 VirtualHost

Only add these lines into httpd.confof your apache:

只将这些行添加到httpd.conf您的 apache 中:

<Directory /var/www/sitefolder/public>
  AllowOverride All
  allow from all
  Options +Indexes
</Directory>

Or you can replace the first line with:

或者您可以将第一行替换为:

<Directory />

And if all doesn't work, you can try:

如果一切都不起作用,您可以尝试:

<Directory />
    Options FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>