3

I have a question, how I can achieve the following result by creating a URL-Rewrite Rule. On wwwroot, I have the folder wordpress/demo that is accessible on e.g. www.example.com/wordpress/demo. However, I want to make this page accessible under www.example.com/example using URL-Rewrite rules.

I already searched a lot, but unfortunately, I have not found a solution yet. Do you have any idea?

DS87
  • 536
  • 3
  • 9
  • 29

2 Answers2

4

So if you don't have it already please install URL Rewrite IIS module:

http://www.iis.net/downloads/microsoft/url-rewrite

After you install it open your web.config file and inside <system.webServer> paste this code:

        <rewrite>
            <rules>
                <rule name="ExampleToDemo">
                    <match url="^(.*)example" />
                    <action type="Rewrite" url="wordpress/demo" />
                </rule>
            </rules>
        </rewrite>

I'm not sure about your structure but this one should work. You can also test it with "Test pattern" feature in IIS Url rewrite module.

IMujagic
  • 1,229
  • 10
  • 22
  • Thanks for your answer. This also worked out for me. I finally created a virtual folder with and inserted the physical path to the virtual folder. That also worked out for me. – DS87 May 18 '16 at 12:37
  • Above scenario can fail if i want to redirect from example.com/folder-name to example.com/blog/folder-name. as it is only matching folder-name that can exist in more than one place in website – Heemanshu Bhalla Feb 25 '18 at 04:28
0

For a more complex case when you pass api params as route variables: If you are using IIS management panel select your domain, the click module "URL Rewrite".

Add Rule -> Blank Rule

Enter name for this rule

Select Append query string

Pattern: ^directoryfrom/([_0-9a-z-]+)/([_0-9a-z-]+)

Rewrite URL: newsubdir/{R:1}/{R:2}

Result: example.com/directoryfrom/{R:1}/{R:2} -> example.com/newsubdir/{R:1}/{R:2}

You may guess about r1 and r2, theses are subfolders you might have passed they will be converted auto into variables.

Community
  • 1
  • 1
Nick Kovalsky
  • 5,378
  • 2
  • 23
  • 50