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>
Related
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>
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>
Is it possible to create a URL rewrite that places the content of a subfolder in the root?
Example:
/pages/article1 would be reached from /article1
/pages/otherstuff would be reached from /otherstuff
I don't want to use virtual directories, because we're talking about hundreds of static pages in the /pages folder.
I found the answer myself... This did the trick:
<rule name="RemoveSEOFolder" stopProcessing="true">
<match url="^seo$|^seo/(.*)$" />
<conditions>
</conditions>
<action type="Redirect" url="seo/{R:1}" />
</rule>
<rule name="RewriteToFile">
<match url="^(?!seo/)(.*)" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="seo/{R:1}" />
</rule>
I've been trying to create user-friendly urls for two of my cfm pages using url rewrite module on IIS 8. That said, there seems to be some sort of conflict due to similarity between rules or something.
Here is what I want to achieve. The following pages:
www.mywebsite.com/news.cfm?category=microsoft
www.mywebsite.com/news.cfm?category=apple
etc
www.mywebsite.com/blog.cfm?title=sometitle
www.mywebsite.com/blog.cfm?title=sometitle
etc
Should look like this:
www.mywebsite.com/news/microsoft
or this
www.mywebsite.com/microsoft
www.mywebsite.com/blog/sometitle
or this
www.mywebsite.com/sometitle
You get the picture.
Here is my code:
<rule name="RedirectUserFriendlyURL4" stopProcessing="true">
<match url="^news\.cfm$" />
<conditions>
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
<add input="{QUERY_STRING}" pattern="^category=([^=&]+)$" />
</conditions>
<action type="Redirect" url="news/{C:1}" appendQueryString="false" />
</rule>
<rule name="RewriteUserFriendlyURL4" stopProcessing="true">
<match url="^news/([^/]+)/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="news.cfm?category={R:1}" />
</rule>
<rule name="RedirectUserFriendlyURL5" stopProcessing="true">
<match url="^blog\.cfm$" />
<conditions>
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
<add input="{QUERY_STRING}" pattern="^title=([^=&]+)$" />
</conditions>
<action type="Redirect" url="blog/{C:1}" appendQueryString="false" />
</rule>
<rule name="RewriteUserFriendlyURL5" stopProcessing="true">
<match url="^blog/([^/]+)/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="blog.cfm?title={R:1}" />
</rule>
The rules above do not work together and both pages redirect to the one that's set in the first rule. Can this be done with a single rule or do I need to use two? How can I sort this out? I would really appreciate your help on this one. I am using ColdFusion 10 on Windows and IIS 8.
Here is the IIS rewriting rule for some URLs to process:
<rule name="rule" stopProcessing="true">
<match url="^(word|world|hero|about)[/]?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/info.aspx?id={R:1}" />
</rule>
How can I create an opposite rule? For example, I want to process all URLs except "/special", "/escape". This:
<rule name="rule" stopProcessing="true">
<match url="^(?!(special)&?!(escape))[/]?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/info.aspx?id={R:1}" />
</rule>
does not work. "/special" and "/escape" URLs are processed as they should, but other URLs give me 404 pages.
You have to use the negate attribute in this case.
Your rule will become:
<rule name="rule" stopProcessing="true">
<match url="^(special|escape)/?$" negate="true" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/info.aspx?id={R:1}" />
</rule>