IIS URL rewrite not work for remove trailing slash - iis

I need to add "Remove trailing slash" if this slash is 2 or more.
Using this Regex pattern (.*)/{2,}$ works in test pattern but does not work on live environment.
For example:
https://test.com/ => https://test.com/
https://test.com// => https://test.com/
https://test.com////// => https://test.com/

There is a problem with the parameters you are using, you can try this rule:
<rule name="test" stopProcessing="true">
<match url="^(.*?)//+(.*)$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Redirect" url="{R:1}/" redirectType="Temporary" />
</rule>

Related

Rewrite rule for a folder/page name without an extension

I have a rewrite rule that doesn't seem to be working as I anticipated. I'm redirected to a 404. It seems to only work if I have an extension on the page.
/folder/page.html works but /folder/page doesn't.
<rule name="preact" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_URI}" pattern="^/(docs)" negate="true" />
</conditions>
<action type="Rewrite" url="index.html" />
</rule>

Simple URL rewrite rule for IIS

I need a simple URL rewrite rule for IIS. If the URL doesn't include "/i" after the domain, I would like to add it.
For Example:
If www.abc.com/sample/test.aspx
I need the rule to change it to:
www.abc.com/i/sample/test.aspx
Your rule should be like that:
<rule name="prepend i">
<match url=".*" />
<conditions>
<add input="{REQUEST_URI}" pattern="^/i/" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Redirect" url="/i/{R:0}" />
</rule>

URL Rewrite - Remove End of URL If Matches Specific String

Using URL rewrite and we have lots of old URLs which take the form
/something/else/index.cfm
/this/that/index.cfm
What I would like to do is remove the /index.cfm from these examples
Any ideas?
Thanks
<rule name="Remove Trailing Index.cfm" enabled="true">
<match url="^(.*)/index.cfm" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{R:1}" pattern="category" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Redirect" url="/{R:1}" />
</rule>

How to rewrite base path (i.e. "/") with IIS rewrite?

How do I rewrite site's base path (i.e. /) using IIS rewrite?
I've tried this so far:
<rule name="RewriteIndexUrl" 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="index.html" />
</rule>
Currently it's not rewriting that base path, and it's returning the index.html directly.
I could figure out a possible solution and it worked:
Remove all default documents in IIS site (i.e. index.html, index.htm, default.aspx...)
Add the following rewriting rule:
<rule name="RewriteIndexUrl" stopProcessing="true">
<match url="^" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="false" />
</conditions>
<action type="Rewrite" url="index.html" />
</rule>

Specific Redirect/Rewrite Rule for web.config

Can someone assist with a redirect rule?
I would like to swap any occurrence of, say, "newjersey", anywhere in the url for "new-jersey".
Any suggestions on how to do this via web.config would be great, as I need to do this right away. TIA!
Got it working via the following:
<rule name="Redirect {1}/newjersey" stopProcessing="true">
<match url="^([^/]+)/newjersey$" ignoreCase="false" />
<conditions trackAllCaptures="true">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Redirect" url="/{R:1}/new-jersey" appendQueryString="false" />

Resources