Asp.Net on IIS - Add default route to url - asp.net

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>

Related

Website URL mapping from ASP.Net URL to MVC URL to redirect

We would like to redirect users from below URL
http://mywebsite.com/Account.asp?Number=25191108
To
http://anotherwebsite.com/Account/25191108
Please let me know if we can do it by config at IIS level or in web.config
You can use URL Rewrite module in IIS to achieve this. You can install it from here.
Add the following rule in your web.config file under "system.webServer" tag.
Let me know if it breaks or if you have any questions around this.
<rewrite>
<rules>
<clear />
<rule name="sample2" stopProcessing="true">
<match url="(.*).asp(.*)Number=(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Redirect" url="http://anotherWebsite.com/{R:1}/{R:3}" redirectType="Temporary" />
</rule>
</rules>
</rewrite>

Can I make this web.config rewrite rule?

In web.config I would like to set up the following rule for my ASP.NET project:
A request to:
mydomain.com/123/some-page
returns page
mydomain.com/collection/123-some-page.html
In other words
domain/x/y should fetch and return domain/collection/x-y.html
The visitor should still see the domain/x/y in the browser url.
Can I make such a rewrite rule?
Remember to install url rewrite module in IIS
and set below rule in web.config
<rewrite>
<rules>
<rule name="My rewrite">
<match url="^(.*)/(.*)$" />
<action type="Rewrite" url="collection/{R:1}-{R:2}.html" />
</rule>
</rules>
</rewrite>

IIS7.5 Direct all requests to one page

I wish to create a site that returns the same html page for all page requests.
For example the same page will be served for all the below requests:
http://holdingsite
http://holdingsite/foo
http://holdingsite/foo/bar
http://holdingsite/foo.aspx
http://holdingsite/foo.html
What configuration is needed to ensure every request is directed to this one page?
If you can, install the URL Rewrite Module
You can then add a rewrite rule to you config
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="catchall" stopProcessing="true">
<match url=".*" />
<action type="Rewrite" url="/somepage.htm" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
N.b You can also configure this via IIS once you have installed the module

How to redirect a url only with specific parameters in IIS

I have a url that looks like this:
www.mywebsite.com/page.aspx?code=1.a
I want to redirect this URL via IIS to:
www.mywebsite.com/page.aspx?code=1.b
I would like to do this through IIS and not within the code.
I have various other website urls that look like:
www.mywebsite.com/page.aspx?code=2
www.mywebsite.com/page.aspx?code=3.a
www.mywebsite.com/page.aspx?code=6.c
I don't want these to be affected.
Thanks.
An easy way to do this in IIS 7.5 is to install the URL Rewrite extension from Microsoft into IIS.
http://www.iis.net/downloads/microsoft/url-rewrite
Once you have it installed, you can just add a rule to redirect from ?code=1.a to ?code=1.b. In IIS, you'll see a new entry called URL Rewrite under the IIS heading for your website. You can use the editor there to create a new rule. Once the rule is created, it will be written into your web.config file.
In the web.config file, the rule should look something like this:
<system.webServer>
...
<rewrite>
<rules>
<rule name="Code=1.a redirect" patternSyntax="ExactMatch"
stopProcessing="true">
<match url="page.aspx" />
<action type="Redirect" url="page.aspx?code=1.b"
appendQueryString="false" redirectType="Permanent" />
<conditions>
<add input="{QUERY_STRING}" pattern="code=1.a" />
</conditions>
</rule>
</rules>
</rewrite>
...
</system.webServer>

iis7 redirect from exact url to new site

I want to re-direct from an exact URL request to a new site within that domain.
I need to re-direct requests from
www.example.com/site111/default.aspx?configX.xml
(this site uses a different config file to load content)
to
www.example.com/site222/default.aspx
Issue is that I need to leave access www.example.com.au/site111/default.aspx
so I cannot just to a http re-direct as there is no file called default.aspx?configX.xml
I think I need to use a URL rewrite re-direct
Can someone help me with the syntax for the web config I cannot get it to work
0 module installed and have used the above syntax and it still doesn't work,
If I use the test feature on the module it says that the string matches,
very confused,
the actual webconfig section is here
<rewrite>
<rules>
<rule name="Redirect2" stopProcessing="true">
<match url="\/nrmmaps\/default.aspx\?config=nrmproject.xml$" />
<action type="Redirect" url="/nrmproject/default.aspx" redirectType="Permanent"/>
</rule>
</rules>
</rewrite>
and the old link is
http://se.nrmspace.com.au/nrmmaps/default.aspx?config=nrmproject.xml
and I want it to re-direct to
http://se.nrmspace.com.au/nrmproject/default.aspx
Do you have any idea why this is not working?
I believe you need to install the IIS rewrite module which can be found here:
http://www.iis.net/downloads/microsoft/url-rewrite
After you do that, you can add a rewrite section with a redirect rule in your web.config like so:
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect" stopProcessing="true">
<match url="\/site111\/default.aspx\?configX.xml$" />
<action type="Redirect" url="/site222/default.aspx" redirectType="Permanent"/>
</rule>
</rules>
</rewrite>
</system.webServer>
Hope this helps

Resources