How to write the Apache Rewrite rules

RewriteEngine on

RewriteEngine on is the representative of open rewrite and RewriteBase / said all the rules before "/", written after the beginning, behind you all the rules, just write "^" after, but it is important to note that this rule is only supported in the.Htacess file, if the server is the configuration file, this rule will be ignored, do not have to write. It is written in the rule, first as special characters talk about the meaning of the design to override.

* represents in front of 0 or more characters

RewriteRule ^b/ ([0-9]+) / $/b.php id=$1 [L]

: so if we want to "贵族宝贝***贵族宝贝/b.php? Id=1" URL "贵族宝贝***贵族宝贝/b/1 this kind of pseudo static" form, while the rules are as follows:

. As the representative of any wildcard character

first, first rewrite rules URL how to write. This is mainly used for pseudo static. Rewrite rules is placed in.Htaccess file or Apache configuration file (httpd.conf or sites_conf directory of some specific sites, configuration files) this paper mainly discuss the.Htacess file (in fact almost).

The start position

often see a lot of people for help, said his IDC does not support the control panel 301 how to do, or ask pseudo static rules how to write, so write this blog, this paper mainly discussed in Apache, prepared by Rewrite rules.

open your.Htacess file, beginning as follows:

on behalf of the end of the string.

? Represents in front of 0 or 1 characters

in the above example, ^ represents the beginning of domain later URL, denotes the end of the string, domain name is behind the end of URL. [0-9] said a number, because if URL exists, it exists a digital ID. Subsequent + indicates the occurrence of 1 or more numbers. [0-9]+>

will follow the character, to restore the character itself, such as " + acts" representative is "+", rather than the other.

+ representative in front of 1 or more characters

^ represents a stringThe position of

RewriteBase /

^ expressed in square brackets – meaning. For example [^.] represents non wildcard.

??

Leave a Reply

Your email address will not be published. Required fields are marked *