Pseudo-static web.config common rule writing and parameter introduction

Pseudo-static web.config common rule writing and parameter introduction.

Example 1:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="规则 1" stopProcessing="true">
                    <match url="^includes/(.*)" />
                    <action type="Rewrite" url="includes\/{R:1}" />
                </rule>
    <rule name="规则 2" stopProcessing="true">
                    <match url="^(blog)/includes/(.*)" />
                    <action type="Rewrite" url="{R:1}/includes\/{R:2}" />
                </rule>
                <rule name="规则 3" stopProcessing="true">
                    <match url="^(blog)/(.*).html(.*)" />
                    <action type="Rewrite" url="{R:1}/index.php\/{R:2}.html{R:3}" />
                </rule>
                <rule name="规则 4" stopProcessing="true">
                    <match url="^(.*).html(.*)" />
                    <action type="Rewrite" url="index.php\/{R:1}.html{R:2}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

Example 2:

<?xml version="1.0" encoding="UTF-8"?>

<configuration>

  <system.webServer>

    <rewrite>

      <rules>

        <rule name="Imported Rule 1">

          <match url="list-([0-9]+)\.html" ignoreCase="false"/>

          <action type="Rewrite" url="plus/list.php?tid={R:1}" appendQueryString="false"/>

        </rule>

        <rule name="Imported Rule 2">

          <match url="list-([0-9]+)-([0-9]+)-([0-9]+)\.html" ignoreCase="false"/>

          <action type="Rewrite" url="plus/list.php?tid={R:1}&TotalResult={R:2}&PageNo={R:3}" appendQueryString="false"/>

        </rule>

        <rule name="Imported Rule 3">

          <match url="view-([0-9]+)-([0-9]+)\.html" ignoreCase="false"/>

          <action type="Rewrite" url="plus/view.php?arcID={R:1}&pageno={R:2}" appendQueryString="false"/>

        </rule>

      </rules>

    </rewrite>

  </system.webServer>

</configuration>

Example 3:

<?xml version="1.0" encoding="UTF-8"?>

<configuration>

  <system.webServer>

    <rewrite>

      <rules>

        <rule name="portal_topic">

          <match url="^(.*/)*topic-(.+).html\?*(.*)$"/>

          <action type="Rewrite" url="{R:1}/portal.php?mod=topic&topic={R:2}&{R:3}"/>

        </rule>

        <rule name="portal_article">

          <match url="^(.*/)*article-([0-9]+)-([0-9]+).html\?*(.*)$"/>

          <action type="Rewrite" url="{R:1}/portal.php?mod=view&aid={R:2}&page={R:3}&{R:4}"/>

        </rule>

        <rule name="forum_forumdisplay">

          <match url="^(.*/)*forum-(\w+)-([0-9]+).html\?*(.*)$"/>

          <action type="Rewrite" url="{R:1}/forum.php?mod=forumdisplay&fid={R:2}&page={R:3}&{R:4}"/>

        </rule>

        <rule name="forum_viewthread">

          <match url="^(.*/)*thread-([0-9]+)-([0-9]+)-([0-9]+).html\?*(.*)$"/>

          <action type="Rewrite" url="{R:1}/forum.php?mod=viewthread&tid={R:2}&extra=page%3D{R:4}&page={R:3}&{R:5}"/>

        </rule>

        <rule name="group_group">

          <match url="^(.*/)*group-([0-9]+)-([0-9]+).html\?*(.*)$"/>

          <action type="Rewrite" url="{R:1}/forum.php?mod=group&fid={R:2}&page={R:3}&{R:4}"/>

        </rule>

        <rule name="home_space">

          <match url="^(.*/)*space-(username|uid)-(.+).html\?*(.*)$"/>

          <action type="Rewrite" url="{R:1}/home.php?mod=space&{R:2}={R:3}&{R:4}"/>

        </rule>

        <rule name="home_blog">

          <match url="^(.*/)*blog-([0-9]+)-([0-9]+).html\?*(.*)$"/>

          <action type="Rewrite" url="{R:1}/home.php?mod=space&uid={R:2}&do=blog&id={R:3}&{R:4}"/>

        </rule>

        <rule name="forum_archiver">

          <match url="^(.*/)*(fid|tid)-([0-9]+).html\?*(.*)$"/>

          <action type="Rewrite" url="{R:1}/index.php?action={R:2}&value={R:3}&{R:4}"/>

        </rule>

        <rule name="plugin">

          <match url="^(.*/)*([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+).html\?*(.*)$"/>

          <action type="Rewrite" url="{R:1}/plugin.php?id={R:2}:{R:3}&{R:4}"/>

        </rule>

      </rules>

    </rewrite>

  </system.webServer>

</configuration>

Tip 1. <rule>The name of the node cannot be repeated.

Tip 2. <match>The url in it is a regular expression, and the example ^(.*)t/([0-9,a-z]*)is a commonly used sentence pattern.

^Match the beginning of the domain name, such as: https://tony.8952.com/, note that there is a slash after the domain name /.

(.*)matches any character.

([0-9,a-z]*)Matches any number and letter.

Therefore, ^(.*)t/([0-9,a-z]*) the following URLs can be matched (if the domain name of the website is tony.8952.com):

Tip 3. <action type="Rewrite" ...>It means that the type of execution is rewriting, and the url inside is the actual url. {R:1}/list.asp?id={R:2} The explanation is as follows:

{R:1}Corresponding to <match>the content of the first parenthesis of the url in , {R:2}corresponding to <match>the content of the second parenthesis of the url in , if there are {R:3}, {R:4}, and so on.

So, if the URL that the user visits is

http://tony.8952.com/t/123
http://tony.8952.com/news/t/a1

Then, the corresponding actual URL is

http://tony.8952.com/list.asp?id=123
http://tony.8952.com/news/list.asp?id=a1

Tip 4. According to the above explanation, you should be able to understand the rule2 rewriting rules of the instance.

$, which is a terminator, indicating that the matched url ends here, and there are no other characters behind it.

([0-9]+) means match any number.

\.html Indicates a match  .html.

\?means match a question mark ?.

In particular, note that the backslash \is an escape character, because in a regular expression, a dot .means matching any character, so you need to add a backslash to escape it, so that it means a dot is matched ..

Similarly, a question mark ?is also a meta-symbol, which means matching the previous subexpression zero or one time. Therefore, an escape character needs to be added in front of it, \which means that a question mark is matched ?.

Tip 5. Others

ignoreCase="false" Indicates that case cannot be ignored. If the value is set true, it means that case is ignored.

appendQueryString="false" Indicates that no url parameters are used.

 MR Virtual Live

Live Streaming Without Latency

Video Encryption and Security

Online director station

Guess you like

Origin blog.csdn.net/ffffffff8/article/details/132710482