【问题标题】:Change default url php更改默认网址 php
【发布时间】:2026-01-24 05:40:01
【问题描述】:

如何更改默认网址。例如 www.example.com/index.php -> www.example.com

现在我想将其设置为 www.example.com/test.php。我应该在 php.ini 中进行更改吗?

【问题讨论】:

  • 这是在您的 Web 服务器中处理的,而不是在 PHP 中。您使用的是 Apache 还是其他?
  • 我猜最简单的方法是创建一个链接。
  • 是的,我正在使用 apache。有它的配置文件吗?
  • 是的,它通常被命名为httpd.conf

标签: php httpd.conf


【解决方案1】:

您可以将 htaccess DirectoryIndex 设置为包含 test.php:

DirectoryIndex test.php index.php index.html

您还可以从 index.php 设置重定向:

header('Location: test.php'); //Must be before any content is sent out

重定向也可以从 htaccess 工作:

Redirect 301 index.php test.php

然而,最简单的做法是将 test.php 文件重命名为 index.php。为什么不这样做呢? :P

【讨论】:

    【解决方案2】:
    DirectoryIndex test.php
    

    在您的 .htaccess 或 httpd.conf 中

    【讨论】:

      【解决方案3】:

      您必须使用 DirectoryIndex 指令在 Apache 的配置中更改此设置。

      例如(在正确的VirtualHost 部分):

      DirectoryIndex test.php 
      

      虽然我不明白为什么要这样做......

      【讨论】:

        【解决方案4】:

        假设你使用的是 apache,你可以通过 DirectoryIndex 指令来做到这一点。

        Check out the docs.

        【讨论】: