jribeiro
jribeiro

Reputation: 3463

IIS - Redirect all requests from one domain to a specific folder

I have a website configured on IIS and multiple domains configured on my hosts file to point to my localhost.

My problem is that I need to redirect all the requests from: http://domain.com/folder/ to http://domain.com/

So a request for http://domain.com/folder/test/image.jpeg should be transformed into: http://domain.com/test/image.jpeg

I can't change the files because I'm trying to emulate a cdn behavior.

Can anyone help?

Thanks Joao

Upvotes: 0

Views: 1473

Answers (1)

cheesemacfly
cheesemacfly

Reputation: 11762

Using the rewrite module, you can go with:

<rule name="skip folder" stopProcessing="true">
    <match url="^folder/(.*)$" />
    <action type="Redirect" url="{R:1}" />
</rule>

The default redirect is a permanent (301).
If you want to keep the url http://domain.com/folder/test/image.jpeg but display the content http://domain.com/test/image.jpeg, then a rewrite has to be used:

<rule name="skip folder" stopProcessing="true">
    <match url="^folder/(.*)$" />
    <action type="Rewrite" url="{R:1}" />
</rule>

Upvotes: 2

Related Questions