【问题标题】:My Laravel Routes is not working on CentOS我的 Laravel 路线不适用于 CentOS
【发布时间】:2019-02-04 15:53:05
【问题描述】:

我刚刚在 CentOS 中制作了一个简单的 laravel 应用程序,在 apache 服务器上运行。问题是我总是出错:

重定向到其他页面时“未找到”。

我该如何解决这个问题?我对使用 CentOS 和 apache 服务器完全陌生。

注意:它适用于 Windows 和 xampp。

这是我的 .htaccess 文件

RewriteEngine On

# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^(.*)/$ /$1 [L,R=301]

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

【问题讨论】:

  • 添加一点代码以便我可以提供帮助
  • 我刚刚添加了我的 .htaccess 文件
  • 请分享项目结构的屏幕截图

标签: laravel centos


【解决方案1】:

用 index.php 试试这条路线?像 yourdomain.com/index.php/route-url 并检查它是否有效。如果您的主页可以正常工作而其他页面不可以,那么您的重写规则没有设置。

sudo a2enmod rewrite on 

你的服务器终端,然后重启 apache

  • 在 Apache 虚拟主机部分添加
AllowOverride all

在你的 laravel 的 .htaccess 中添加这个:

Options +FollowSymLinks -Indexes
RewriteEngine On

RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

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

【讨论】:

  • 是的,我的主页有效,但其他页面无效。已经将 mod_rewrite 设置为“on”和“AllowOverride”。但是,当我执行“php artisan serve”时,即使在 CentOS 上也能完美运行
  • 你能在 index.php 中做一次 phpinfo() 并检查 mod rewrites 是否显示为启用吗?
  • 我应该看到什么?很抱歉我对这个完全陌生
  • 您可以检查是否在启用的 php 模块中提到了 mod_rewrites
  • 您是否将 AllowOverride All 添加到 /etc/httpd/conf/httpd.conf 中?
【解决方案2】:

您可能没有设置 Apache 来正确重写您的路由并将其交给 index.php 文件。查看this 页面底部附近的 Apache 部分,并确保您的重定向反映了该页面的布局。

【讨论】:

  • 你能把 Apache 配置粘贴到这个线程中,也许你的 .env 也可以吗?
  • 我正在关注 laravel 文档指南中的 apache 配置
猜你喜欢
  • 2017-04-20
  • 1970-01-01
  • 1970-01-01
  • 2020-05-16
  • 1970-01-01
  • 2014-06-04
  • 1970-01-01
  • 2015-12-24
  • 2023-01-10
相关资源
最近更新 更多