URL Rewrite - remove the .html extension

So, the idea is to remove the .html extension from each page so ...

www.website.com/File.html > www.website.com/File www.website.com/Folder/File.html > www.website.com/Folder/File 

Now I managed to do this using the Rewrite URL, but that means writing a rewrite for each page, which is time consuming, inefficient and impractical if the site exceeds 20 pages.

Is there a way to do this by writing only one or two rewrites in the web.config file?

+6
source share
2 answers

This solution ultimately worked for me:

 <rule name="RedirectUserFriendlyURL1" stopProcessing="true"> <match url="^(.*)\.(.*)$" /> <conditions> <add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" /> </conditions> <action type="Redirect" url="{R:1}" appendQueryString="false" /> </rule> <rule name="RewriteUserFriendlyURL1" stopProcessing="true"> <match url="^(.*)$" /> <conditions> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> </conditions> <action type="Rewrite" url="{R:1}.(.*)" /> </rule> 
+9
source

Use the rewrite module for IIS 7.x:
http://www.techrepublic.com/blog/webmaster/url-rewriting-with-iiss-url-rewrite-module/710

Although I tried this, I never got the actual rule to automatically execute without having a rule for the page name.

+1 to anyone who can shed light on this!

0
source

Source: https://habr.com/ru/post/913534/


All Articles