【问题标题】:How to resolve PHP page not found on LiteSpeed server如何解决在 LiteSpeed 服务器上找不到 PHP 页面
【发布时间】:2020-01-04 11:38:32
【问题描述】:

我有一个 PHP 文件的以下布局

├── classes/
├── migrations/
├── public/
│   ├── images/
│   ├── scripts/
│   ├── styles/
│   └── index.php
├── sample/
└── templates/

我不知道如何将它放在我的服务器上,所以我将 public 中的文件放入了我的 public_html 文件夹(这是我的 cPanel 已经拥有的)。

另外,我把其他目录和public_html放在同一层级,以保持项目的正常结构。

因此,我最终得到了这个:

├── (some cPanel directory and files)
├── classes/
├── migrations/
├── public_html/
│   ├── images/
│   ├── scripts/
│   ├── styles/
│   └── index.php
├── sample/
├── templates/
└── (other cPanel directory and files)

现在,除索引页外,所有其他页面都返回 HTTP 状态代码 404。

我做错了什么?

作为参考,我正在尝试部署的项目位于https://github.com/srv-twry/Quizzer

【问题讨论】:

  • 您可以更改您网站的文档根目录吗?
  • 将您的网站定位到example.com/index.php,这行得通吗?可以访问日志吗?放置在文档根目录中的任何 Php 文件是否按预期运行?
  • 也许您需要使用 .htaccess 进行重定向并重写规则?假设这个服务器是 Apache。您在开发时如何运行您的网站?
  • 它正在处理 index.php(因为它看起来正在使用您的代码),只是您的路由没有考虑 URL 中的 index.php。你所缺少的只是一些我认为的重写规则。
  • 试试这样的:webmasters.stackexchange.com/a/57316/89012,但是看起来你正在运行一个 litespeed 服务器,所以配置可能会有所不同。检查手册和/或您的托管服务提供商。

标签: php litespeed


【解决方案1】:

在您的源中没有.htaccess,听起来好像缺少重定向。

您需要通过前端控制器路由适当的 URL - index.php

对于 Apache 风格的服务器,您可以使用 modrewrite.htaccess 文件。

作为起点,使用以下规则创建.htaccess - 您可能需要根据个人需求进行调整;

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-s
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php [NC,L]

Webmasters Stackexchange复制的代码。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-12
    • 2017-09-23
    • 1970-01-01
    • 2017-03-14
    • 1970-01-01
    • 2015-02-05
    • 2021-02-24
    • 1970-01-01
    相关资源
    最近更新 更多