【问题标题】:How to style 404 page in WAMP server如何在 WAMP 服务器中设置 404 页面的样式
【发布时间】:2012-07-30 00:49:19
【问题描述】:

我正在使用 WAMP 服务器,我需要使用 CSS 更改“404 未找到页面”样式。我该怎么做?

【问题讨论】:

    标签: php html css http-status-code-404 wamp


    【解决方案1】:

    如果您的服务器上托管了许多站点,并且您希望每个站点都有不同的消息,则添加 ErrorDocument 404 到 .htaccess 文件是要走的路。

    如果您希望所有网站都出现相同的错误消息,那么在 httpd.conf 中设置 ErrorDocument 是可行的方法。

    【讨论】:

      【解决方案2】:

      在您的httpd.conf 文件中,将有一个ErrorDocument 部分:

      #
      # Customizable error responses come in three flavors:
      # 1) plain text 2) local redirects 3) external redirects
      #
      # Some examples:
      #ErrorDocument 500 "The server made a boo boo."
      #ErrorDocument 404 /missing.html
      #ErrorDocument 404 "/cgi-bin/missing_handler.pl"
      #ErrorDocument 402 http://www.example.com/subscription_info.html
      #
      

      之后,添加以下代码:

      ErrorDocument 404 /error.html
      

      这会将错误页面设置为一个名为error.html 的文件,这比使用.htaccess 文件要好。

      【讨论】:

        【解决方案3】:

        您可以使用 .htaccess 文件将 404 错误页面重定向到您的自定义页面。

        使用 HTML/CSS 设计您的自定义 404 页面。设置 404 页面后,您需要做的就是将访问者发送到此页面的错误 URL。为此,只需将以下行添加到您的 .htaccess 文件中:

        ErrorDocument 404 /404.php
        

        您可以将 404 错误模板放置在您想要的任何位置。例如,您可以将所有错误消息放在一个名为 errormessages

        的文件夹中
        ErrorDocument 404 /errormessages/404.php 
        

        见这篇文章,How to redirect your 404 error to a custom page

        【讨论】:

          【解决方案4】:

          在.htaccess中添加

          ErrorDocument 404 /path/to/custom/404.php
          

          【讨论】:

            【解决方案5】:

            这是 Apache 中的 core feature,您可以选择几种更改 404 消息的方法。

            要使用 HTML/CSS 创建您自己的自定义页面,这是您可以放入 .htaccess 文件中的一个选项:

            ErrorDocument 404 /my404.php
            

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 2013-07-07
              • 1970-01-01
              • 1970-01-01
              • 2015-05-22
              • 2013-08-15
              • 2012-04-02
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多