IIS 7 url rewrite module on web.config - asp.net

can anybody help me with this please. I have IIS7 and the hosting says that the URL Rewrite module has been installed already. I even put into the bin directory the Microsoft.Web.Iis.Rewrite.dll
i can only use the web.config for the url rewrite configuration since I dont have access to the IIS manager (hosting restriction).
here is my code on the web.config:
<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite to list_cities.aspx">
<match url="^/state/([a-zA-Z]+)" />
<action type="Rewrite" url="~/list_cities.aspx?state={R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
I still get the error, HTTP Error 404.0 - Not Found, when i go to
http://xxxxxxxx.com/state/CA/ . I have already searched the issue but I cant seem to find any solutions.
Can anybody please check my code. Thanks a lot.

I found the solution just now (not being an IIS expert...)
Change {R:1} for {R:0}
<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite to list_cities.aspx">
<match url="^/state/([a-zA-Z]+)" />
<action type="Rewrite" url="~/list_cities.aspx?state={R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>

Related

IIS 8 Rewrite Rules for Folder

I have Asp.Net project. My project physical path structure as /htdocs/site1/...
I would like to change this url request as /site1/...
I have put below codes into to webconfig but it is not working. Currently IIS 8 rewrite extension installed on web server
<system.webServer>
<rewrite>
<rules>
<rule name="htdocs_remove">
<match url="/htdocs/site1/" />
<action type="Rewrite" url="/site1/" />
</rule>
</rules>
</rewrite>
</system.webServer>
Restart IIS and try again. If it fails to work then follow this ref-1 and ref-2.

Asp.Net on IIS - Add default route to url

I am trying to change the default URL of my Asp.Net website on IIS. At the moment the URL leading to the default index.html, is just http://myservername/. But I would actually prefer to extend the URL to http://myservername/route1, which then still routes to the default html. How can I achieve this?
Download Microsoft URL Rewrite Module and install it
and add this to your web.config
<system.webServer>
<rewrite>
<rules>
<rule name="Root Hit Redirect" stopProcessing="true">
<match url="^$" />
<action type="Redirect" url="/route1" />
</rule>
</rules>
</rewrite>
</system.webServer>

IIS URL Redirect works, but Rewrite throws 403 forbidden error

I have a web.config file in a subdirectory of an IIS application like this
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Proxy2" stopProcessing="true" patternSyntax="Wildcard">
<match url="*" ignoreCase="true"/>
<conditions>
<add input="{HTTP_HOST}" pattern="*" />
</conditions>
<action type="Rewrite" url="http://anotherurl.com/{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
so, if I browse https://www.abc.com/subdir , it will return 403 forbidden error. but if I change the action to redirect, it will redirect without problems. what should I look for to find the problem?
It's not possible to rewrite to another URL (or another Application Pool). Only redirect will work in this case.
Edit: Technically it's possible, but not the way you've implemented it. If you want to rewrite to another URL, you'll need to implement as a reverse proxy using the Application Request Routing (ARR) module in IIS.

iis redirect subdomain to subfolder on same subdomain

I have an IIS site and Im trying to use ReWrite 2.0 to redirect a particular subdomain to a sub folder. Within my IIS site I have it binded to two different domains:
one.example.com
two.example.com
When people visit one.example.com I want it to do nothing. When people visit http://two.example.com I want them to be redirected to http://two.example.com/subfolder.
Thanks for your help.
You need to add a match condition for the HTTP_HOST
<system.webServer>
<rewrite>
<rules>
<rule name="two.example.com Redirect" stopProcessing="false">
<match url="^\/?$" />
<conditions>
<add input="{HTTP_HOST}" pattern=".*two\.example\.com.*" />
</conditions>
<action type="Redirect" redirectType="Found" url="http://two.example.com/subfolder/{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
Here's a decent overall reference for the module:
http://www.iis.net/learn/extensions/url-rewrite-module/url-rewrite-module-configuration-reference
A very late answer, but hopefully it helps someone.
I presume you are using II7 or higher ?
IIS has a simple HTTP redirect function which is available per site listed in IIS.
Make sure you are in features view. Click on the site you want to redirect (In your case its http://two.example.com)
You should see this. Double click on HTTP Redirect
The you should see this. Enter your Redirect URL here (In your case its http://two.example.com/subfolder)
This existing question should solve your issue
<system.webServer>
<rewrite>
<rules>
<rule name="Root Hit Redirect" stopProcessing="true">
<match url="^$" />
<action type="Redirect" url="/menu_1/MainScreen.aspx" />
</rule>
</rules>
</rewrite>
</system.webServer>

URLRewrite IIS 7 Help Needed

Here is my settings for IIS 7 URL Rewrite:
<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite to article.aspx">
<match url="^Articles/([0-9]+)/([_0-9a-z-]+)" />
<action type="Rewrite" url="articledetails.aspx?articleid={R:1}&title={R:2}" />
</rule>
</rules>
</rewrite>
</system.webServer>
Unfortunately, my page at the following url is not displayed at all:
http://www.highoncoding.com/Articles/723_Introduction_to_IPhone_Development.aspx
Looks like you are giving in the wrong URL.
<match url="^Articles/([0-9]+)/([_0-9a-z-]+)" />
The above rule will match /Articles/723/Introduction_to_Iphone_Development. You are giving it /Articles/723_Introduction_to_Iphone_Development (underscore instead of slash). Seems that you fixed it as I am typing this though :)

Resources