Apache open pseudo static method to share _linux

Source: Internet
Author: User

Environment:
System Windows
Apache 2.2

Load Rewrite module:

Found in httpd.conf in the Conf directory

Copy Code code as follows:

LoadModule Rewrite_module modules/mod_rewrite.so

This sentence, remove the front annotation symbol "#", or add this sentence.

Allow the ". htaccess" file to be used in any directory and change "allowoverride" to "all" (Default "None"):

Copy Code code as follows:

# AllowOverride Controls What directives may is placed in. htaccess files.
# It can be ' all ', ' None ', or any combination of the keywords:
# Options FileInfo authconfig Limit
#
AllowOverride All

You cannot create a ". htaccess" file directly under Windows System, you can use "echo a>. htaccess" at the command line to create it, and then use Notepad to edit it.

The simple application of the Apache rewrite module:
All of the rewrite rules are based on Perl-style regular expressions, and the following basic examples can be used to write code that matches their jump requirements.

1, request to jump

The purpose is to jump to another domain name if the request is a. jsp file.

For example: Visit www.jb51.net/a.php jump to b.jb51.net/b.php page, Access www.jb51.net/news/index.php to b.jb51.net/news/index.php page

Note: It is not using meta or JavaScript in HTML technology, because www.jb51.net/a.php this file does not exist, with the rewrite module in the Apache2.2 server.

Modify the. htaccess or apche configuration file httpd.conf file, add the following

Copy Code code as follows:

Rewriteengine on
#开启Rewrite模块
Rewriterule (. *) \.php$ http://b.jb51.net/$1\.jsp [R=301,L,NC]
#截获所有. JSP request, jump to http://b.jb51.net/plus the original request plus. php. r=301 is 301 jump, l for rewrite rule to terminate, NC is case-insensitive

2, Domain name jump

If the request is for all URLs under Old.jb51.net, jump to B.jb51.net

Copy Code code as follows:

Rewriteengine on
#开启Rewrite模块
Rewritecond%{remote_host} ^old.studenthome.cn$ [NC]
#针对host为old. Jb51.net host to do processing, ^ for start character, $ for end character
Rewriterule (. *) http://b.jb51.net/$1 [R=301,L,NC]

3, anti-theft chain

If the images on this site do not want to be called by other sites, you can add the following in the. htaccess or Apche profile httpd.conf file

Copy Code code as follows:

Rewriteengine on
#开启Rewrite模块
Rewritecond%{http_referer}!^$
#如果不是直接输入图片地址
Rewritecond%{http_referer}!img.jb51.net$ [NC]
#且如果不是img. jb51.net all child domain names called by
Rewritecond%{http_referer}!img.jb51.net/(. *) $ [NC]
Rewritecond%{http_referer}!zhuaxia.com [NC]
Rewritecond%{http_referer}!google.com [NC]
Rewritecond%{http_referer}!google.cn [NC]
Rewritecond%{http_referer}!baidu.com [NC]
Rewritecond%{http_referer}!feedsky.com [NC]
Rewriterule (. *) \. (jpg|jpeg|jpe|gif|bmp|png|wma|mp3|wav|avi|mp4|flv|swf) $ http://clin003.com/err.jpg [R=301,L,NC]
#截获所有. jpg or. jpeg ... Request, jump to http://clin003.com/err.jpg hint wrong picture, note: This picture cannot be under the original domain name, also cannot be in the folder that the. htaccess file is effectively controlled

4, do not need to define the. htaccess file

Add on apache2\conf\httpd.conf last line

Copy Code code as follows:

Rewriteengine on
Rewriterule ^ (. *)-htm-(. *) $ $1.php?$2

Restart Apache
Login background Open All false

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.