When you just play the Web page, you write a static page http://uicss.cn/about.htm such a structure.
Then I wanted to change to http://uicss.cn/about/.
But also because unfamiliar rewrite, did the following adjustment, manually set up a pile of folders:
Such a directory structure, maintenance is quite troublesome. Each time you add a new page, you open a folder.
In fact, using the structure on the left to deploy, the server to set up a little, you can support the URL we want to effect.
How to play rewrite
First look at your server for support. htaccess
If you support this product, you do not have to write a rule every time to restart the server, easy to test.
redirect 301 /test.htm http://uicss.cn/
Success, when you visit the xxx.com/test.htm, will automatically jump to my blog.
If you don't succeed, you need to open it. htaccess:
- Open \conf\httpd.conf, find #LoadModule rewrite_module, remove #, load the module
- Open \conf\extra\httpd-vhosts.conf, look for allowoverride none, change none to all
After the environment is ready to complete, also need to "pattern match" in the special characters in the interpretation of the rewrite to do understand:
* 代表前面0或更多个字符
+ 代表前面1或更多个字符
? 代表前面0或1个字符
^ 代表字符串的开始位置
^ 在方括号里代表“非”,例如[^/]代表非斜杠。
$ 代表字符串结束的位置
. 代表任何字符(也就是通配符)
\ 取消后面字符的特殊意思,转为原义字符。
—— 这部分的理解出自《SEO艺术》第六章末
Let's do it, open it. htaccess's rewrite
RewriteEngine on
Replace the xxx.htm file with the xxx/
RewriteRule ^(.*)\/$ /$1.htm [L]
To give an example a deeper understanding, this is to replace the xxx.php file on the server with the xxx.html
RewriteRule ^(.*)\.html$ /$1.php [L]
More usage:
Let all users accessing www.uicss.cn/xxx/jump to uicss.cn/xxx/
RewriteCond %{HTTP_HOST} ^www.uicss.cn [NC]
RewriteRule ^(.*)$ http://uicss.cn/$1 [L,R=301]
Code to turn on the specified directory:
RewriteBase /top/
Steering with search parameters:
RewriteRule ^search/(.+)?$ /index.php?s=$1 [QSA,L]
End of directory Slash:
RewriteRule ^(.+[^/])$ /$1/ [R]