When I first played a webpage, I wrote the structure of the static page http://centoscn.com/about.htm. Later, I want to change it to idea. 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 server.
Just play Web pages, write static pages such as http://centoscn.com/about.htm structure.
Later I want to change to http://centoscn.com/about/
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.
Redirect 301/test.htm http://centoscn.com/
If it succeeds, when you access xxx.com/test.htm, it will automatically jump to my blog.
If it fails, you need to enable. htaccess:
- Open \ conf \ httpd. conf and find#LoadModule rewrite_module, remove #, and load this module
- Open \ conf \ extra \ httpd-vhosts.conf to find AllowOverrideNone, 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)
\ Cancel 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.
RewriteEngine on
Replace xxx.htm with xxx/
RewriteRule ^ (.*)\/$/Define 1.htm [L]
Let's give another example to better understand. this is to replace the xxx. PHP file on the server with xxx.html.
RewriteRule ^ (.*)\. Html$/$ 1.php [L]
More methods:
Redirect all users accessing www.centoscn.com/xxx/ to centoscn.com/xxx/
RewriteCond % {HTTP_HOST} ^ www.centoscn.com [NC]
RewriteRule ^ (. *) $ http://centoscn.com/#1 [L, 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]