. htaccess files Topsy rewrite

Source: Internet
Author: User

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:

    1. Open \conf\httpd.conf, find #LoadModule rewrite_module, remove #, load the module
    2. 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]



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.