开发者

Always show the same HTML page

How can I always show the same static HTML page no matter what URL of the same domain is being entered? I use 开发者_如何转开发IIS7


URL rewriting should do the trick for you. First you'll need to install the URL rewrite module, assuming it's not installed already: http://www.iis.net/download/urlrewrite

Next, add the following in the system.webServer section of your web.config:

<rewrite>
    <rules>
        <rule name="Main Rule" stopProcessing="true">
            <match url=".*" />
            <conditions logicalGrouping="MatchAll">
                <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
            </conditions>
            <action type="Rewrite" url="YOUR_PAGE_HERE.html" />
        </rule>
    </rules>
</rewrite>

Obviously, replace YOUR_PAGE_HERE.html with the page you wish to display. This ruleset will display your static page for any URL that's not a directory or another file. If you want all urls to display this page, simply remove the whole <conditions> element. Just not that if you're linking to images or stylesheets, they to will serve up your static page.

For more info on URL rewriting, I recommend the following resources:

  1. http://learn.iis.net/page.aspx/460/using-the-url-rewrite-module/
  2. http://learn.iis.net/page.aspx/466/enabling-pretty-permalinks-in-wordpress/


you can try this way:

<rewrite>
  <rules>
    <rule name="Hide .html ext">
      <match url="^(.*)" ignoreCase="true" />
      <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        <add input="{REQUEST_FILENAME}.html" matchType="IsFile" />
      </conditions>
      <action type="Rewrite" url="{R:0}.html" />
    </rule>
    <rule name="Redirecting .html ext" stopProcessing="true">
      <match url="^(.*).html" />
      <conditions logicalGrouping="MatchAny">
        <add input="{URL}" pattern="(.*).html"  />
      </conditions>
      <action type="Redirect" url="{R:1}" />
    </rule>
  </rules>
</rewrite>

I recommended following resource: https://www.youtube.com/watch?v=0hlTdi6qijQ

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜