URL Rewrite IIS - Map From One Path To Another - iis

I am playing with URL rewrite in IIS 7
The behaviour I want is when someone types in
[http://localhost/Sales]
they get redirected to [http://localhost/SalesDemo]
but they still see [http://localhost/Sales] in the browser URL
Is this possible?

The best way to achieve that would be to use Rewrite Maps in URL Rewrite Module.
Alternatively you could add rewrite section to your web.config file.
Web.config example:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite rule">
<match url="^Sales$" />
<action type="Rewrite" url="SalesDemo" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Please note that the action type needs to be Rewrite (and not Redirect) if you still want to see /Sales in your browser.
I hope that will help.

Related

web.config: URL rewrite to remove directory

So currently I've got the URL websitename.com/posts/post
and I would like to change it to websitename.com/post
I've been trying now for 3 days with no luck. Seen loads of stuff for .htaccess but not much for web.config
Apologies in advance as I'm sure I'm asking a really dumb question,
Thank you!
Maybe this is what you want. Put it in the root directory of your website. You could also change Rewrite to Redirect there.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="posts" patternSyntax="ExactMatch">
<match url="/posts/post" />
<action type="Rewrite" url="/post" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

How can I get IIS to redirect to a virtual application if no path is specified?

My IIS setup has one site, bound to a domain. Let's call it: www.mydomain.com
The site folder itself is empty. This site hosts multiple applications and virtual directories. One of the applications is 'portal'.
What I want to do is accept any incoming request for www.mydomain.com or www.mydomain.com/ and redirect it to: www.mydomain.com/portal
I've got ARR and URL Rewrites up and running. I'm just not sure how to configure them for this.
A redirection rule like below will work.
Put the following web.config file to your web site's root folder. Or, update the existing one if you have.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="toPortal" stopProcessing="true">
<match url="^$" />
<action type="Redirect" url="/portal" redirectType="Found" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
You may want look at this tutorial to learn how to create url rewrite rules with IIS Manager. These xml nodes are not coming from my brain too.

IIS URL Rewrite mobile folder

Hi I have a site that used to have a separate mobile side which had links indexed by google. I’ve now changed that to a responsive design. I’m on a shared server so I have to do this redirect through URL Rewrite, is there any way that I can redirect anything and everything that comes after the /mobile/ subfolder that used to exist to its equivalent in a root folder with one rule. So that the following would happen:
Domain.com/mobile -> domain.com
Domain.com/mobile/folder1/page1/variable -> domain.com/folder1/page1/variable
Domain.com/mobile/folder1/page2/variable -> domain.com/folder1/page2/variable
Domain.com/mobile/folder2/page1/variable -> domain.com/folder2/page1/variable
Domain.com/mobile/folder2/page2/variable -> domain.com/folder2/page2/variable
That would look something like the following in your web.config (basicall match all "root" requests that start with mobile/ and redirect to the equivalent (using a 301 which is the right one for SEO purposes):
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect mobile" stopProcessing="true">
<match url="^mobile/(.*)$" />
<action type="Redirect" url="{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

IIS UrlRewrite - Only works one actual file exists

I have the following url rewrite code in my web.config
I want to forward anything .htm to the brand.aspx.
so if anyone type in
test1.htm
test2.htm
test3.htm
would go to the brand.aspx. However, the following url rewrite would work if there is an actual file call "test1.htm" in the server, then it will redirect to the brand.aspx. If there is no file exists, it will just return 404 instead of redirect to the brand.aspx. Does anybody know why? thanks a lot.
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="test" stopProcessing="false">
<match url="(.*)\.htm$" ignoreCase="true" />
<action type="Rewrite" url="brand.aspx" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
There is a similar thread
Using a custom URL rewriter, IIS6, and urls with .htm, .html, etc
I have experienced a similar issue before and i made a custom IHTTPModule
for which i used the guide at
http://msdn.microsoft.com/en-us/library/ms227673.aspx

IIS: How can I redirect requests for one page to another?

I have written an app to replace a single page and need to redirect the requests for the old page to the new app.
In IIS, how would I redirect the request for
http://www.mysite.com/foo.aspx
to
http://www.mysite.com/bar/default.aspx
Thanks!
In your web.config do:
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Foo_To_Bar" stopProcessing="true">
<match url="^foo.aspx" />
<action type="Redirect" url="/bar/default.aspx" redirectType="Temporary" />
</rule>
</rules>
</rewrite>
</system.webServer>
If you don't want to write the redirects by hand, there is a tool for URL Rewrite and Redirects: http://www.iis.net/learn/extensions/url-rewrite-module/using-the-url-rewrite-module The installer says it is for 7.0 but it works with 8.5 as well.
What you need is URL rewriting. There are a number of options. Some are discussed in this question:
IIS URL Rewriting vs URL Routing

Resources