Rewrite rules how to write the Apache article

Source: Internet
Author: User
Keywords Apache Multiplayer

Intermediary transaction http://www.aliyun.com/zixun/aggregation/6858.html ">seo diagnose Taobao guest cloud host technology Hall

Often see a lot of people for help, said his IDC does not support the Control Panel do 301 How to do, or to ask the pseudo static rules how to write, so write this blog, mainly in this article mainly discussed in Apache, to write rewrite rules.

First, let's say how the URL rewrite rules are written. This is mainly used for pseudo static. The overriding rule is a specific Web site configuration file that is placed under the. htaccess file or in the Apache configuration file (httpd.conf or sites_conf directory), which is mainly discussed in this article. htacess files (in fact, all the same).

Open your. htacess file, beginning with the following:

Rewriteengine on

Rewritebase/

Rewriteengine on is on behalf of the Open rewrite, and rewritebase/is all the rules before the "/", after writing this, you have all the rules at the beginning of all, only to write "^" on the later, but note that This rule is only supported in. htacess files, and if it is a server configuration file, this rule is ignored and not written. Before you write the rules, let's talk about the meaning of the special characters designed in the rewrite.

* Represents front 0 or more characters

+ represents front 1 or more characters

? Represents the front 0 or 1 characters

^ represents the starting position of a string

The position where the end of the string is represented

. For wildcard characters, representing any character

\ Restores the character followed by the character itself, for example, "\+" means "+", not other meanings.

^ mean in square brackets. For example [^.] Represents a non-wildcard character.

So if we want to "Http://www.***.com/b.php?id=1″ this kind of URL pseudo static as" Http://www.***.com/b/1″, the rules are as follows:

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

In the example above, ^ represents the beginning of a later URL for a domain name, and $ means the end of the string, which is the end of the URL after the domain name. [0-9] Represents a number because, as long as the URL exists, there must be an ID number. Immediately following the + indicates that 1 or more digits appear. [0-9]+ is joined together to denote that the character appears as a number, with a range of 0-9 and 1 or more occurrences. $ indicates the end of the string,? $ is 0 or 1 characters after the root domain to the end of the domain name. Represents the presence of content in memory, i.e. the contents of the first parenthesis. [L] means that if a rule match is stopped, it is necessary to continue running the remaining rules, which is usually unnecessary.

That unless pseudo static, 8630.html "> Sometimes we need to use. htacess for 301 redirects. The symbolic meaning does not change, for example:

Rewriteengine on

Rewritecond%{http_host} ^seozhao\.com$ [NC]

Rewriterule ^ (. *) http://www.***.com/$1 [r=301,l]

The above rule is to seozhao.com 301 to www.***.com, and the meaning of the symbol is believed to need no further explanation.

So after these two rules, you should have inspired, if your site to do a revision, resulting in your URL structure has changed, how to do? The answer is simple, we can use the. htacess file, by writing rewrite rules, the old URL 301 to the new URL.

Rewriterule ^ (. *?) /?index\.html$/$1? [l,r=301]

This rule is to search the domain under the URL of a/index.html 301 to A/A/. The rule is dead, the most important thing is everybody wants to ingenious, believed grasps the rewrite rule, you will discover the website all URL and the return code will be all under your control!

This article Tianjin seo:http://www.seozhao.com/135.html reprint please specify

Related Article

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.