Home Backend Development PHP Tutorial php网站404错误页面的写法

php网站404错误页面的写法

Jun 20, 2016 pm 01:04 PM
php website

每个网站基本上都不会少404这个页面,404页面的作用是在用户访问你网站中某个不存在的页面或者无法访问的页面的时候,这个时候通过404页面给当前用户一个友好明确的答复。告诉他这个地址是不存在的,并告诉他接来下该怎么办。

在php程序中,我们也经常需要考虑如何用php实现页面404跳转的写法,下面作者将如何用php进行404转向的写法和大家分享一下!

<p>@header("http/1.1 404 not found");</p>@header("status: 404 not found");<br />echo 'echo 404';//直接输出页面错误信息<br />exit();或者:@header("http/1.1 404 not found");<br />@header("status: 404 not found");<br />include("http://www.scutephp.com/404.html");<br />//跳转到某一个页面,推荐使用这种方法,注意include文件的路径不能是网络路径<br /><p>exit();</p>
Copy after login

查看404是否设置成功可以利用 firefox 的 firebug 插件来查看,具体查看方法如下:在已经安装firebug的情况下,用firefox浏览器打开要检查404状态码的页面,点击右下角小虫的图标,启动"网络"标签,依次打开"网络–所有/html–headers";如果一切正常,你就可以看到包括headers、响应在内的各项页面参数了。

另外这里也说下关于 apache 404 错误页面的定义,具体定义方法如下:


在网站的根目录下新建一个 .htaccess 文件,然后在该文件中加入如下内容即可:

ErrorDocument 404 http://www.scutephp.com/404.html
Copy after login


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Optimizing website SEO: practice of pseudo-static hiding php suffix Optimizing website SEO: practice of pseudo-static hiding php suffix Mar 07, 2024 pm 12:27 PM

As we all know, optimizing the SEO of a website is a very important part of website operation. The default URLs of dynamic web systems (such as PHP) used by many websites have extensions (.php, .html, etc.), which will affect the SEO effect of the website. In order to improve the optimization effect of the website, a common practice is to change the dynamic URL to a pseudo-static URL to hide the extension name and improve the user experience and search engine ranking of the website. This article will take "pseudo-static hidden php suffix" as the theme, introduce how to achieve this optimization in PHP websites, and

Which websites are developed using php Which websites are developed using php Aug 11, 2023 am 11:03 AM

Websites developed with PHP include: 1. Facebook, one of the world's largest social media platforms; 2. Wikipedia, the world's leading online encyclopedia; 3. WordPress, a widely used open source blog and content management system; 4. Twitter, a popular social media platform; 5. Yahoo, a world-renowned portal; 6. Flickr, an online image hosting and sharing platform; 7. LinkedIn, a professional social media platform.

What is the development method of Empire CMS template? What is the development method of Empire CMS template? Apr 17, 2024 am 12:09 AM

Empire cms template development methods include: 1. Understand the template structure; 2. Modify the template code; 3. Use tags and variables; 4. Create custom functions; 5. Use CSS and JS; 6. Use template modules; 7. Debugging and test.

Which websites are made with php Which websites are made with php Aug 11, 2023 am 10:55 AM

Websites made with PHP include: 1. Facebook, one of the world's largest social media platforms; 2. Wikipedia, an online encyclopedia edited by users around the world; 3. WordPress, a popular open source blog and content management system; 4. Slack, a widely used team collaboration tool; 5. Magento, a powerful open source e-commerce platform; 6. Etsy, an online marketplace for handicrafts and independent designers.

Build a simple website in php Build a simple website in php Mar 22, 2024 pm 03:04 PM

Building a PHP website involves the following steps: 1. Prepare the environment, install the PHP development environment and create the website root directory. 2. Create the basic file structure, including the homepage index.php and other required files. 3. Write home page content, use HTML and PHP to build page structure and dynamically generate content. 4. Add other pages and create other PHP files to process page content. 5. Connect to the database (optional), use PHP to connect to the database and operate the data. 6. Design styles and interactive effects, and use CSS and JavaScript to enhance the beauty and interactivity of the website. 7. Deploy the website and upload the website files to the server or

How to use encryption algorithm to protect user data of PHP website? How to use encryption algorithm to protect user data of PHP website? Aug 19, 2023 pm 04:00 PM

How to use encryption algorithm to protect user data of PHP website? With the rapid development of the Internet, user data protection of websites has become more and more important. In PHP development, we can use encryption algorithms to protect the security of user data. This article will introduce some commonly used encryption algorithms and how to use them in PHP websites to encrypt user data. 1. Selection of encryption algorithms For PHP websites, we can choose the following commonly used encryption algorithms to protect the security of user data: 1. Symmetric encryption algorithm: This algorithm uses the same encryption algorithm.

How to protect your PHP website using secure coding practices? How to protect your PHP website using secure coding practices? Aug 20, 2023 pm 06:05 PM

How to protect your PHP website using secure coding practices? With the popularity and development of the Internet, more and more websites use PHP as the development language. However, PHP's flexibility and ease of use also make it vulnerable to various security threats. Therefore, when developing a PHP website, it is essential to apply secure coding practices to protect the website from possible attacks. This article will introduce some ways to protect your PHP website using secure coding practices and provide corresponding code examples. Input Validation and Filtering Input Validation and Filtering is the key to protecting PHP websites

PHP website security and protection measures PHP website security and protection measures May 04, 2024 pm 10:48 PM

PHP website security measures include: Preventing SQL injection: using prepared statements or escaping user input. Prevent XSS: Escape user input. Prevent CSRF: Use CSRF tokens. Prevent buffer overflow: Set the maximum input length. Stay updated, use security frameworks, enable firewalls, monitor websites, conduct security audits.

See all articles