PHP 404 page/How to set 404 page/url static/url pseudo-static

Source: Internet
Author: User

How to set 404 pages and other error pages in PHP

First create a new file under the project root, with the file name " . htaccess "

Write the configuration entry in the file:

ErrorDocument 404/404.html or an address with a file path: errordocument 404/error_pages/404.html

Other errors 401, 500 and so on.

Note The point is: (reference)

Do not point the error page to the main page, which may cause the homepage to disappear from the search engine;

The error page address is set with a relative path (if there is an absolute address, it will return two requests, the first is 302 redirects, redirect to the absolute address page you set, the page returns 200) (self test)

. htaccess page Other settings ( reference )

Setting up page 301 Redirection

REDIRECT #从 Old_dir directory to the New_dir directory
Redirect/old_dir/http://www.yourdomain.com/new_dir/index.html
#把通过二级目录访问的请求301重定向到二级域名
Redirectmatch 301/dir/(. *) http://dir.yourdomain.com/$1

Prohibit user access to the specified IP segment

IP Access #禁止 IP for 255.0.0.0 and 123.45.6. Segments
Order Allow,deny
Deny from 255.0.0.0
Deny from 123.45.6.
Allow from all

Prohibit specified source page access

Source Access #禁止从 otherdomain.com and anotherdomain.com
Rewriteengine on
# Options +followsymlinks
Rewritecond%{http_referer} otherdomain\.com [Nc,or]
Rewritecond%{http_referer} anotherdomain\.com
Rewriterule. *–[f]

Picture anti-theft chain settings

#从本站以外的域名访问图片, show feed.jpg
Rewriteengine on
Rewritecond%{http_referer}!^$
Rewritecond%{http_referer}!^http://(www\.)? yourdomain.com/.*$ [NC]
Rewriterule \. (gif|jpg|png) $ http://www.yourdomain.com/feed.jpg [r,l]

Set folder home page

#防止显示文件夹列表, when the folder is accessed, the server looks for index.html and makes it the first page file, if it does not exist, and then looks backwards
DirectoryIndex index.html index.cgi index.php

Set up multimedia files for download and not playback

AddType application/octet-stream. mp3. mp4

Custom HTTP Header

Header set X-pingback "http://www.yourdomain.com/xmlrpc.php"
Header set article-by "YourDomain.com"

Set file expiration Time Cache Control

# Enable Expiration control
Expiresactive on
# gif/png/jpg valid for 1 months
Expiresbytype image/gif "Access plus 1 month"
Expiresbytype image/png "Access plus 1 month"
Expiresbytype image/jpg "Access plus 1 month"
# js/css valid for 1 weeks
Expiresbytype text/javascript "Access plus 1 week"
Expiresbytype text/css "Access plus 1 week"

WordPress Build Station program pseudo-static code

# begin WordPress #这是一行注释, which means WordPress htaccess starts here
#如果Apache加载了mod_rewrite. C module, run the following code
Rewriteengine on #启用 mod_rewrite engine
rewritebase/#设置目录重写的基准URL为/
Rewriterule ^index\.php$–[l] #如果请求路径是 index.php, stop the rewrite operation (avoid a dead loop)
Rewritecond%{request_filename}!-f #如果请求的不是一个文件, continue processing
Rewritecond%{request_filename}!-d #如果请求的不是一个目录, continue processing
Rewriterule. /index.php [L] #把所有的请求指向/index.php
#结束 Ifmodule
# end WordPress #WordPress htaccess here ends

Discuz x3/x3.1 General pseudo-static code

#如果Apache加载了mod_rewrite. C module, run the following code
Rewriteengine on
Rewritebase/discuz
Rewritecond%{query_string} ^ (. *) $
Rewriterule ^topic-(. +) \.html$ portal.php?mod=topic&topic=$1&%1
Rewritecond%{query_string} ^ (. *) $
Rewriterule ^article-([0-9]+)-([0-9]+) \.html$ portal.php?mod=view&aid=$1&page=$2&%1
Rewritecond%{query_string} ^ (. *) $
Rewriterule ^forum-(\w+)-([0-9]+) \.html$ forum.php?mod=forumdisplay&fid=$1&page=$2&%1
Rewritecond%{query_string} ^ (. *) $
Rewriterule ^thread-([0-9]+)-([0-9]+)-([0-9]+] \.html$ forum.php?mod=viewthread&tid=$1&extra=page\%3d$3 &page=$2&%1
Rewritecond%{query_string} ^ (. *) $
Rewriterule ^group-([0-9]+)-([0-9]+) \.html$ forum.php?mod=group&fid=$1&page=$2&%1
Rewritecond%{query_string} ^ (. *) $
Rewriterule ^space-(Username|uid)-(. +) \.html$ home.php?mod=space&$1=$2&%1
Rewritecond%{query_string} ^ (. *) $
Rewriterule ^blog-([0-9]+)-([0-9]+) \.html$ home.php?mod=space&uid=$1&do=blog&id=$2&%1
Rewritecond%{query_string} ^ (. *) $
Rewriterule ^archiver/(Fid|tid)-([0-9]+) \.html$ archiver/index.php?action=$1&value=$2&%1
Rewritecond%{query_string} ^ (. *) $
Rewriterule ^ ([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+) \.html$ plugin.php?id=$1:$2&%1
#结束 Ifmodule

url static/url pseudo-static

Reference http://blog.csdn.net/shuiaaa/article/details/6561793

Since this content has not been tested, so do not give their own notes

PHP 404 page/How to set 404 page/url static/url pseudo-static

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.