Simple IIS URL Rewrite needed

skbohler
skbohler used Ask the Experts™
on
Hello,

I need to create a simple IIS URL Rewrite rule that does the following:

If user accesses http (or https)://folder1/filea.asp

Redirect user to: http (or https)://folder2/filea.asp

Thanks in advance,

Steve
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Olivier MARCHETTACitrix Support and Infrastructure Engineer

Commented:
Hello. You can install the IIS rewrite module from this page :
https://www.iis.net/downloads/microsoft/url-rewrite

Then you can use this guide :
https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/creating-rewrite-rules-for-the-url-rewrite-module

1. Create a default website
2. Open the URL Rewrite module in the webpage configuration panel
3. Create a blank rule
4. Enter the pattern or the expression you want to rewrite.
Ryan ChongSoftware Team Lead

Commented:
try and see if this work for you in http / https?

(tested working in http)

<rule name="RewriteUserFriendlyURL" enabled="true" stopProcessing="true">
                    <match url="^folder1/([^/]+)/?$" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
                    <action type="Redirect" url="folder2/{R:1}" appendQueryString="false" />
                </rule>

Open in new window

Author

Commented:
Hi Ryan,
Thanks for the reply.

Does that rule work for both http and https?

I have a finite list of URLs that I need to redirect from one directory to another. So, I believe I the matchURL should be something more specific than <match url="^folder1/([^/]+)/?$" />, no?

Wouldn't that rule apply to all files in folder1?
OWASP: Forgery and Phishing

Learn the techniques to avoid forgery and phishing attacks and the types of attacks an application or network may face.

Ryan ChongSoftware Team Lead

Commented:
Does that rule work for both http and https?
you probably can try it out, as I don't have a https site for testing. it should worked for both http and https.

Wouldn't that rule apply to all files in folder1?
yes
Ryan ChongSoftware Team Lead

Commented:
any further clarification is needed here?

Author

Commented:
I needed a versions that works for a specific file in a specific directory. Not all files in a specific directory. How can I achieve that?

Thank you.
Software Team Lead
Commented:
>>a specific file
do you mean filea.asp?

if you only required http (or https)://folder1/filea.asp to be redirected to http (or https)://folder2/filea.asp

then you can try a fixed rule:

<rule name="RewriteUserFriendlyURL" enabled="true" stopProcessing="true">
                    <match url="folder1/filea.asp" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
                    <action type="Redirect" url="folder2/filea.asp" appendQueryString="false" />
                </rule>

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial