Parameter directory, which will be like www.abc.com/store/store… Such a website, external change to http://www.abc.com/1024.

This can be done in one of three ways (and not only in these three ways!).

\

1. Rewrite module 2.0 with Microsoft URL, but only for IIS7, not IIS6.

64:

www.microsoft.com/downloads/z…

32:

www.microsoft.com/zh-cn/downl…

2, isapi_rewrite

www.helicontech.com/download-is… \

But the full version has a date limit, if you don’t want to pay, you can use the following:

Download.csdn.net/detail/keke… \

3, urlrewriter.net

This has source code, you can compile it yourself.

\

As luck would have it, I used methods one and two. Because the development machine is WIN7, installed IIS7, so with Microsoft rewrite module; For Windows 2003, isAPI_rewrite was used.

Here are two methods to do a little experience respectively.

In fact, these two methods are very much the same, IIS is basically a little bit less configuration, not as mysterious as the Internet says, there are checks, there are mappings, there are permissions and so on, the key is to write the right regular expression.

\

1. Microsoft URL rewriting module 2.0\

Once installed, you can rewrite the web.config under the web site.

<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0"/>
    <httpRuntime/>
  </system.web>
  <system.webServer>
    <rewrite>
      <rules>
	<! - http://localhost/1024 = = > http://localhost/store/store.aspx? id=1024 -->
        <rule name="storecode">
          <match url="^ ((1-9] [0-9] *) /? $" ignoreCase="true"/>
          <action type="Rewrite" url="/store/store.aspx? id={R:1}"/>
        </rule>
	<! - http://localhost/1024/p=1&c=1 = = > http://localhost/store/store.aspx? id=1024&p=1&c=1 -->
        <rule name="storecode with param">
          <match url="^ ((1-9] [0-9] *)/([^ /] +) /? $" ignoreCase="true"/>
          <action type="Rewrite" url="/store/store.aspx? id={R:1}&{R:2}"/>
        </rule>
	<! -- The following is said to be derived from the Discuz forum and must be correct for learning -->
        <!--
                <rule name="已导入的规则 1">
                    <match url="^userinfo-([0-9]+)\.html$" ignoreCase="false" />
                    <action type="Rewrite" url="userinfo.aspx?userid={R:1}" 

appendQueryString="false" />
                </rule>
                <rule name="已导入的规则 2">
                    <match url="^showforum-([0-9]+)\.html$" ignoreCase="false" />
                    <action type="Rewrite" url="showforum.aspx?forumid={R:1}" 

appendQueryString="false" />
                </rule>
                <rule name="已导入的规则 3">
                    <match url="^showtopic-([0-9]+)\.html$" ignoreCase="false" />
                    <action type="Rewrite" url="showtopic.aspx?topicid={R:1}" 

appendQueryString="false" />
                </rule>
                <rule name="已导入的规则 4">
                    <match url="^showforum-([0-9]+)-([0-9]+)\.html$" ignoreCase="false" />
                    <action type="Rewrite" url="showforum.aspx?forumid={R:1}&page=

{R:2}" appendQueryString="false" />
                </rule>
                <rule name="已导入的规则 5">
                    <match url="^showtopic-([0-9]+)-([0-9]+)\.html$" ignoreCase="false" />
                    <action type="Rewrite" url="showtopic.aspx?topicid={R:1}&page=

{R:2}" appendQueryString="false" />
                </rule>
                <rule name="已导入的规则 6">
                    <match url="^archiver/showforum-([0-9]+)\.html$" ignoreCase="false" />
                    <action type="Rewrite" url="archiver/showforum.aspx?forumid={R:1}" 

appendQueryString="false" />
                </rule>
                <rule name="已导入的规则 7">
                    <match url="^archiver/showtopic-([0-9]+)\.html$" ignoreCase="false" />
                    <action type="Rewrite" url="archiver/showtopic.aspx?topicid={R:1}" 

appendQueryString="false" />
                </rule>
                <rule name="已导入的规则 8">
                    <match url="^archiver/showtopic-([0-9]+)-([0-9]+)\.html$" 

ignoreCase="false" />
                    <action type="Rewrite" url="archiver/showtopic.aspx?topicid={R:1}

&page={R:2}" appendQueryString="false" />
                </rule>
                <rule name="已导入的规则 9">
                    <match url="^archiver/showforum-([0-9]+)-([0-9]+)\.html$" 

ignoreCase="false" />
                    <action type="Rewrite" url="archiver/showforum.aspx?forumid={R:1}

&page={R:2}" appendQueryString="false" />
                </rule>
                <rule name="已导入的规则 10">
                    <match url="^tools/rss-([0-9]+)\.html$" ignoreCase="false" />
                    <action type="Rewrite" url="tools/rss.aspx?forumid={R:1}" 

appendQueryString="false" />
                </rule>
                <rule name="已导入的规则 11">
                    <match url="^tools/spacerss-([0-9]+)\.html$" ignoreCase="false" />
                    <action type="Rewrite" url="tools/rss.aspx?uid={R:1}&type=space" 

appendQueryString="false" />
                </rule>
                <rule name="已导入的规则 12">
                    <match url="^tools/photorss-([0-9]+)\.html$" ignoreCase="false" />
                    <action type="Rewrite" url="tools/rss.aspx?uid={R:1}&type=photo" 

appendQueryString="false" />
                </rule>
                <rule name="已导入的规则 13">
                    <match url="^space\/((\w|\s)+)((\/?))?$" ignoreCase="false" />
                    <action type="Rewrite" url="space/index.aspx?user={R:1}" 

appendQueryString="false" />
                </rule>
                <rule name="已导入的规则 14">
                    <match url="^space\/((\w|\s|-)+)((\/?))?\?((.*)+)$" ignoreCase="false" 

/>
                    <action type="Rewrite" url="space/index.aspx?user={R:1}&{R:5}" 

appendQueryString="false" />
                </rule>
                <rule name="已导入的规则 15">
                    <match url="^showdebate-([0-9]+)\.html$" ignoreCase="false" />
                    <action type="Rewrite" url="showdebate.aspx?topicid={R:1}" 

appendQueryString="false" />
                </rule>
                <rule name="已导入的规则 16">
                    <match url="^showbonus-([0-9]+)\.html$" ignoreCase="false" />
                    <action type="Rewrite" url="showbonus.aspx?topicid={R:1}" 

appendQueryString="false" />
                </rule>
                <rule name="已导入的规则 17">
                    <match url="^postgoods-(\d+)*.html$" ignoreCase="false" />
                    <action type="Rewrite" url="postgoods.aspx?categoryid={R:1}" 

appendQueryString="false" />
                </rule>
                <rule name="已导入的规则 18">
                    <match url="^showgoodslist-(\d+)(-(\d+))?.html$" ignoreCase="false" />
                    <action type="Rewrite" url="showgoodslist.aspx?categoryid={R:1}

&page={R:3}" appendQueryString="false" />
                </rule>
                <rule name="已导入的规则 19">
                    <match url="^showgoods-(\d+)*.html$" ignoreCase="false" />
                    <action type="Rewrite" url="showgoods.aspx?goodsid={R:1}" 

appendQueryString="false" />
                </rule>
                <rule name="已导入的规则 20">
                    <match url="^install((\/?))?$" ignoreCase="false" />
                    <action type="Rewrite" url="/install{R:1}" />
                </rule>
                <rule name="已导入的规则 21">
                    <match url="^upgrade((\/?))?$" ignoreCase="false" />
                    <action type="Rewrite" url="/upgrade{R:1}" />
                </rule>
                <rule name="已导入的规则 22">
                    <match url="^aspx/([0-9]+)((\/?))?$" ignoreCase="false" />
                    <action type="Rewrite" url="/aspx/{R:1}{R:2}" />
                </rule>
                <rule name="已导入的规则 23">
                    <match url="^archiver((\/?))?$" ignoreCase="false" />
                    <action type="Rewrite" url="/archiver{R:1}" />
                </rule>
                <rule name="已导入的规则 24">
                    <match url="^space((\/?))?$" ignoreCase="false" />
                    <action type="Rewrite" url="/space{R:1}" />
                </rule>
                <rule name="已导入的规则 25">
                    <match url="^doc((\/?))?$" ignoreCase="false" />
                    <action type="Rewrite" url="/doc{R:1}" />
                </rule>
                <rule name="已导入的规则 26">
                    <match url="^(([\w|\-|_])+)((\/?))?$" ignoreCase="false" />
                    <action type="Rewrite" url="/{R:1}/list.aspx" />
                </rule>
                <rule name="已导入的规则 27">
                    <match url="^(([\w|\-|_])+)((\/?))?\?(.)*$" ignoreCase="false" />
                    <action type="Rewrite" url="/{R:1}/list.aspx?{R:2}" 

appendQueryString="false" />
                </rule>
                <rule name="已导入的规则 28">
                    <match url="^(([\w|\-|_])+)/([0-9]+)((\/?))?$" ignoreCase="false" />
                    <action type="Rewrite" url="/{R:1}/{R:3}/list.aspx" />
                </rule>
                <rule name="已导入的规则 29">
                    <match url="^(([\w|\-|_])+)/([0-9]+)((\/?))?\?(.)*$" ignoreCase="false" 

/>
                    <action type="Rewrite" url="/{R:1}/{R:3}/list.aspx?{R:4}" 

appendQueryString="false" />
                </rule>
-->
      </rules>
    </rewrite>
  </system.webServer>
</configuration>
Copy the code

The key is to write the regular expression correctly, otherwise the system will report a 404 error that the resource cannot be found. Damn it. Can’t you report something else? I did a frantic search on the Internet, thinking there was something wrong with the configuration, and almost had IIS reinstalled. The Internet won’t tell you that either, they just suggest removing the option of whether the file exists or not, and so on.

HTTP error 404.0-not Found

The resource you are looking for has been removed, renamed, or temporarily unavailable.

\

Rewrite (within the same site) and Redirect (within another site). Such as

          <rule name="img show">
              <match url="^showimg/([a-zA-Z_0-9]+)/([1-9][0-9]*)/? $" ignoreCase="true"/>
              <action type="Redirect" url="http://localhost:8006/handler.ashx? {R:1}={R:2}"/>
          </rule>
Copy the code


\

2, isapi_rewrite \

Once installed, it’s ready to use. Open IIS6 and click on Site-Properties to see:

\

Clicking EDIT generates an.htaccess file in the root directory of the site. Write our regular expression inside:

# Helicon ISAPI_Rewrite configuration file # Version 3.1.0.87 RewriteRule ^([1-9][0-9]*)/eurl\.axd/ /store.aspx\? id=$1 [NC] RewriteRule ^([1-9][0-9]*)/([^/]*)? /? /store/store.aspx\? id=$1&$2 [NC]Copy the code

\

The syntax for regular expressions doesn’t seem to differ much from Microsoft’s URL rewriting module, and it also comes with a regular expression tester. When you open the.htaccess file, you can see the RegExp test in the editor menu:

\

\

\

\

IIS6 then uses isapi_rewrite.dll as a filter

\

But I found a few caveats:

1. No question mark (” \? “) in regular expressions ), otherwise the match must fail, but the regular expression is absolutely correct, in other regular expression tester, also OK, but not here. I don’t know why. I went through the Internet, and a brother said,

That’s because in the URL, right? The latter is not considered a requested URI by Apache, so you can’t get it. I suggest you change the URL format: for example, put? Get rid of; Or change the fetch method: RewriteRule /? (.*)$ /reg.php? id=$1&%\

Post: bbs.csdn.net/topics/3000… \

But this is IIS! I don’t get it. Whatever. So I originally wanted to set the optimized address to: www.abc.com/1024?p=1&c=…

2, IIS6 +.net 4 case, IIS automatically no suffix (what is no suffix? “/eurl.axd/ GUID “after the address, just like my machine. This would have been removed automatically in ASP.NET processing, but it is still there after being redirected. During my testing, I displayed Request.QueryString on the target page, which was shamefully uninvited:

\

\

Online there are articles on the way to modify the registry to shield

www.admin10000.com/document/12… \

But I thought I might adopt the MVC pattern in the future, so I only took this into account when writing regular expressions:

RewriteRule ^([1-9][0-9]*)/eurl\.axd/ /store/store.aspx\? id=$1 [NC]\

3. Each rule should be followed by an appropriate flag if necessary.

The RewriteRule of isapi_rewrite is the one with the odd notation [NC] or [L]. \

In fact, they are very useful, such as:

[NC], ignore case

[L], in a series of matching rules, when the system finds the first matching rule, it no longer matches other rules. This is especially useful, for example: \

I have rules 1, 2, and 3, and I have an input case where I imagine rule 2 should work, which is the best match, but rule 3 is a superset of Rule 2, which can also match. If rule 2 is not followed by this [L] flag, then rule 3 is in effect!

[R], I feel like it’s faster to Redirect an input to another website.

There are also many flags, which can be found here:

www.helicontech.com/isapi_rewri… \

It’s in English, but as computer programmers, we still have to get used to reading English documents, which is sometimes easier to understand than reading weirdly translated Chinese documents. Sometimes I feel that foreigners are so good at programming and often put forward ideas and patterns because they have no barriers in reading and communication and accept things faster than us. We suffered the loss.

My Own English is very poor, and I am not used to reading English documents, but from now on, I will gradually get used to it. With pig gentleman mutual encouragement!