Initial Experience of Apache. htaccess Rewrite Rules

Source: Internet
Author: User

However, since you are not familiar with rewrite, you have made the following adjustments and created a bunch of folders manually:
  
This directory structure is quite troublesome to maintain. Each time you add a new page, you need to open a folder.
  
In fact, we use the structure on the left to deploy the service. If the server is slightly set, we can support the desired URL effect.
  
How to play rewrite
  
First, check whether your server supports. htaccess.
  
If this product is supported, you do not need to restart the server every time you write a rule to facilitate testing.
  
Http://uicss.cn/redirect301/test.htm/
  
If it succeeds, your access to xxx.com/test.htmwill automatically jump to my blog.
  
If it fails, you need to enable. htaccess:
  
Open confhttpd. conf, find # loadmodulerewrite_module, remove #, and load this module.
  
Open the confextrahttpd-vhosts.conf, find allowoverridenone, and change none to all
  
After the environment is ready, you also need to read the rewrite interpretation of the special characters in "pattern matching:
  
* Represents the first 0 or more characters
  
+ Represents the first 1 or more characters
  
? Represents the first 0 or 1 Character
  
^ Represents the start position of the string
  
^ Represents "not" in square brackets. For example, [^/] represents a non-Slash.
  
$ Indicates the position at which the string ends.
  
. Represents any character (that is, a wildcard)
  
Remove the special meanings of the following characters and convert them to original characters.
  
-- This part of understanding comes from the end of chapter 6 of Seo art.
  
Start. Open rewrite of. htaccess.
  
Rewriteengineon
  
Replace xxx.htm with xxx/
  
Rewriterule ^ (. *)/$/define 1.htm [l]
  
Add another example, replace the xxx.php file on the server with xxx.html
  
Rewriterule ^ (. * pai.html $/$ 1.php[ L]
  
More methods:
  
Allow all users accessing www.test.com/xxx/to access test.com/xxx/
  
Rewritecond % {http_host} ^ test.com [Nc]
  
Rewriterule ^ (. *) $ http://uicss.cn/4101l,r%301]
  
Code for enabling redirection for a specified directory:
  
Rewritebase/top/
  
Redirection with search parameters:
  
Rewriterule ^ search/(. + )? $/Index. php? S = $1 [QSA, l]
  
Slash At the end of the directory:
  
Rewriterule ^ (. + [^/]) $/$1/[R]

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.