I'm trying to setup a IIS 8 Website. I want to ignore the last directory of a typed in url, but not to remove it instead just ignore it. The directory name could be anything

Explanation

Website URL : https://mywebsite.com

The site has a directory named /stores, which has a complete website.
The website will use the non-existent directory /somename in the URL to render the website properly.

If i type in https://mywebsite.com/stores/somestore obviously i will get 404 Not Found as the directory somestore does not exist inside stores

How can i write an IIS Rule to ignore that last part of the URL directory which does not exist but to also keep it in the URL's so it can be used by PHP to render the page properly.

Kind of like Facebook, where a profile is access by adding /profilename to the URL.

NOTE : I cant use URL Parameters for this due to some technical clashes.

Feel free to update the this questions title, i'm not sure if its entirely correct.

1 Answers

1
Brando Zhang On Best Solutions

Basically if you look at the address bar on stackoverflow right now after the folder /questions there is a supposedly directory named ThisQuestionsId (55762513). But in the actual server is there a folder with that name? I assume not. I want to know how this is achieved.

As far as if you want to achieve the url format like stackoverflow by using IIS url rewrite.

I suggest you could refer to below rule.

It will rewrite the https://mywebsite.com/question/55553 to https://mywebsite.com/question.php?id=55553

That means you could write the logic inside the question.php page to select data and show it according to the query string id's value.

  <rewrite>
    <rules>
                <rule name="RewriteUserFriendlyURL1" stopProcessing="true">
                    <match url="^question/([^/]+)/?$" />
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="question.php?id={R:1}" />
                </rule>

    </rules>
  </rewrite>