Rename IIS URL and Web.config

I don’t understand anything about IIS, but I am trying to solve this problem of redirecting all visitors to domain.com/page to domain.com/page.html

<?xml version="1.0" encoding="utf-8" ?> <configuration> <system.webServer> <rewrite> <rewriteMaps> <rewriteMap name="StaticRedirects"> <add key="/page" value="/page.html" /> </rewriteMap> </rewriteMaps> </rewrite> </system.webServer> </configuration> 

There are several problems:

  • I don’t know where to put the file. There is a user root directory and a htdocs directory, I tried both without joy.
  • I don’t even know if the account can rewrite, I am trying to find this.
+49
url-rewriting web-config iis
Dec 10 2018-10-10
source share
3 answers

1) Your existing web.config: you declared a rewrite map .. but did not create any rules that will use it. RewriteMap does absolutely nothing at its own expense.

2) You can do this below (it does not use rewriting cards - only the rules, which is great for a small amount of rewriting / forwarding):

This rule will do SINGLE EXACT rewrite (internal redirection) /page to /page.html . The URL in the browser will remain unchanged.

 <system.webServer> <rewrite> <rules> <rule name="SpecificRewrite" stopProcessing="true"> <match url="^page$" /> <action type="Rewrite" url="/page.html" /> </rule> </rules> </rewrite> </system.webServer> 

This rule No. 2 will do the same as above, but it will perform 301 redirects (permanent redirects), where the URL will be changed in the browser.

 <system.webServer> <rewrite> <rules> <rule name="SpecificRedirect" stopProcessing="true"> <match url="^page$" /> <action type="Redirect" url="/page.html" /> </rule> </rules> </rewrite> </system.webServer> 

Rule No. 3 will try to execute such correspondence for ANY URL if there is such a file with the extension .html (i.e. for /page it will check if /page.html , and if this happens, then it will be rewritten ):

 <system.webServer> <rewrite> <rules> <rule name="DynamicRewrite" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{REQUEST_FILENAME}\.html" matchType="IsFile" /> </conditions> <action type="Rewrite" url="/{R:1}.html" /> </rule> </rules> </rewrite> </system.webServer> 
+108
Jul 19 2018-11-11T00: 00Z
source share

Just wanted to point out one thing missing from LazyOne's answer (I would just comment on the answer, but I don't have enough reputation)

Rule number 2 for permanent redirection is missing a thing:

redirectType="Permanent"

So, rule # 2 should look like this:

 <system.webServer> <rewrite> <rules> <rule name="SpecificRedirect" stopProcessing="true"> <match url="^page$" /> <action type="Redirect" url="/page.html" redirectType="Permanent" /> </rule> </rules> </rewrite> </system.webServer> 

Edit

For more information on how to use the URL rewrite module, see this excellent documentation: Link to the URL rewrite link

In response to the @kneidels question from the comments; To match the URL: topic.php?id=39 you can use something like the following:

 <system.webServer> <rewrite> <rules> <rule name="SpecificRedirect" stopProcessing="true"> <match url="^topic.php$" /> <conditions logicalGrouping="MatchAll"> <add input="{QUERY_STRING}" pattern="(?:id)=(\d{2})" /> </conditions> <action type="Redirect" url="/newpage/{C:1}" appendQueryString="false" redirectType="Permanent" /> </rule> </rules> </rewrite> </system.webServer> 

This will correspond to topic.php?id=ab , where a is any number between 0-9 , and b is also any number between 0-9 . It then redirects to /newpage/xy , where xy comes from the original URL. I have not tested this, but it should work.

+13
Dec 13 '12 at 14:20
source share

I just tried this rule and it worked with GoDaddy hosting, as they already have a module for rewriting Microsoft URLs for each IIS 7 account.

 <rewrite> <rules> <rule name="enquiry" stopProcessing="true"> <match url="^enquiry$" /> <action type="Rewrite" url="/Enquiry.aspx" /> </rule> </rules> </rewrite> 
+10
Jan 14 '12 at 19:40
source share



All Articles