沉冰浮水

沉冰浮水

做最终到的事,成为最终成为的人!
github
bilibili
mastodon
zhihu
douban

"Memo" web.config setting for redirection (301)

2023-01-18: This is an old file, reformatting and updating;

Starting from IIS7.0, it supports some settings through the web.config file, including redirect (301).

You need to install the rewrite component (Rewrite) on the server, download and install it, or ask the hosting provider if it is supported;

URL Rewrite: The Official Microsoft IIS Site

https://www.iis.net/downloads/microsoft/url-rewrite#additionalDownloads

After installation, it can be found in the feature view of the IIS site. In addition to adding rules by yourself, you can also import the .htaccess rules of the original document. However, it is faster to directly copy and modify the example below now.

Create a web.config file in the root directory of the site, then copy the content below (XML code) and paste it in, and modify it as needed. If there is already a web.config file, copy the <rewrite> or <rule> nodes as needed. Multiple URL rules can be set to redirect to the same address. Another line in the <urlCompression> node is to enable GZIP compression.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
      <urlCompression doStaticCompression="true" doDynamicCompression="true" />
      <rewrite>
        <rules>
            <rule name="feed" stopProcessing="true">
                <match url="^(.*)$" />
                <conditions logicalGrouping="MatchAny">
                    <add input="{HTTP_HOST}" pattern="^feed.wdssmq.tk$" />
                    <add input="{HTTP_HOST}" pattern="^feed.wdssmq.com$" />
                    <add input="{URL}" pattern="^/rss.xml$" />
                </conditions>
                <action type="Redirect" redirectType="Permanent"
                    url="https://www.wdssmq.com/feed.php" />
            </rule>
            <rule name="host" stopProcessing="true">
                <match url="^(.*)$" />
                <conditions logicalGrouping="MatchAny">
                    <add input="{HTTP_HOST}" pattern="^wdssmq.tk$" />
                    <add input="{HTTP_HOST}" pattern="^www.wdssmq.tk$" />
                    <add input="{HTTP_HOST}" pattern="^wdssmq.com$" />
                    <add input="{HTTP_HOST}" pattern="^xn--37q595dihas5a.tk$" />
                    <add input="{HTTP_HOST}" pattern="^www.xn--37q595dihas5a.tk$" />
                </conditions>
                <action type="Redirect" redirectType="Permanent"
                    url="https://www.wdssmq.com/{R:0}" />
            </rule>
        </rules>
      </rewrite>
  </system.webServer>
</configuration>

Below is the method of configuring URL redirect (301) through the .htaccess file on a Linux host. MS is simpler, and it is strongly recommended to resubscribe to this site through http://feed.wdssmq.com.

RewriteEngine on

RewriteCond %{http_host} ^feed.wdssmq.tk [NC]
RewriteRule ^(.*)$ http://feed.wdssmq.com$1 [L,R=301]

RewriteCond %{http_host} ^wdssmq.tk [NC,OR]
RewriteCond %{http_host} ^wdssmq.com [NC,OR]
RewriteCond %{http_host} ^www.wdssmq.tk [NC]
RewriteRule ^(.*)$ https://www.wdssmq.com/$1 [L,R=301]

Related articles:

--Memo - Displaying Specific Error Messages in IIS7--

--Memo - How to Enable Parent Paths in Win7--

--Memo - Configuring gzip Compression in IIS7 web.config--

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.