The configuration method of Apache open pseudo-static htaccess in Windows system

Source: Internet
Author: User

System environment: Windows Apache 2.2

Load Rewrite module:

Found in httpd.conf in the Conf directory

The code is as follows Copy Code
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"):

The code is as follows Copy Code
# 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 111cn.net/a.php jump to www.111cn.net/b.php page, Access 111cn.net/news/index.php to www.111cn.net/news/index.php page

Note: It is not using meta or JavaScript in HTML technology, because 111cn.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

The code is as follows Copy Code
Rewriteengine on
#开启Rewrite模块
Rewriterule (. *). php$ http://www.111cn.net/$1.jsp [R=301,L,NC]

#截获所有. JSP request, jump to Http://www.111cn.net/add 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.mrlon.net, jump to Www.111cn.net

The code is as follows Copy Code
Rewriteengine on
#开启Rewrite模块
Rewritecond%{remote_host} ^old.studenthome.cn$ [NC]
#针对host为old. Mrlon.net host to do processing, ^ for start character, $ for end character
Rewriterule (. *) http://www.111cn.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

  code is as follows copy code
rewriteengine On
#开启Rewrite模块
Rewritecond%{http_referer}!^$
#如果不是直接输入图片地址
Rewritecond%{http_referer}! img.mrlon.net$ [NC]
#且如果不是img. mrlon.net
Rewritecond%{http_referer!img.mrlon.net/(. *) $ [NC]
for all subdomain calls 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) $/err.jpg [R=301,L,NC]

#截获所有. jpg or. jpeg ... Request, jump to/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 apache2confhttpd.conf last line

The code is as follows Copy Code

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

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.