【问题标题】:How to structure web pages如何构建网页
【发布时间】:2017-03-31 16:38:06
【问题描述】:

当网站上的页面采用这种结构时,背后的技术是什么? example.com/pages/about

当查看后面的代码时,很明显有问题的页面实际上位于根目录 (example.com) 中,此外,还可以将任何内容附加到 URL(例如 example.com/pages/about/qwerty)和但它仍然返回正确的页面?

我根本不知道用谷歌搜索什么。


我忘了提到,我在经典的 ASP 中工作。事实证明,“语义 URL”是我正在寻找的。为了弥补我对缺乏研究的“不满意”,这是我今天早上想出的一个解决方案:

example.com/about/default.asp:

<%session("jump")="about.asp"
response.redirect "http://example.com"%>

example.com/default.asp 应包括:

<%if len(session("jump"))>0 then server.transfer(session("jump"))%>

这将使语义 URL example.com/about 可用,并且不会向用户显示结果页面的 URL:example.com/about.asp

【问题讨论】:

标签: html iis web asp-classic


【解决方案1】:

您使用的是 Classic ASP,它没有任何已建立的 MVC 框架,因此 MVC 路由可能对您没有太大帮助。您可能应该搜索的是“URL 重写”。有一个纯 ASP 解决方案,它涉及创建自定义 404 页面并在条件语句中使用server.transfer(因此您开始沿着正确的思路思考),但从实际的角度来看,您可能想要使用的是 IIS URL重写模块。

首先,您需要使用 IIS7 或更高版本,我认为我们现在可以放心地假设您会使用,因为 Microsoft 不再支持具有早期版本的操作系统。您可以通过 IIS 管理器添加规则,也可以将它们直接添加到您的 web.config 文件中。例如,如果您希望 example.com/about 将您带到 about.asp,而 example.com/contact 将您带到 contact.asp(这两个文件都在您的根目录中),那么您可以将以下内容添加到 @987654323 @web.config 文件的部分

<rewrite>
      <rules>            
        <rule name="About" stopProcessing="true">
          <match url="^about$"/>
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
          </conditions>
          <action type="Rewrite" url="about.asp"/>
        </rule>
        <rule name="Contact" stopProcessing="true">
          <match url="^contact$"/>
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
          </conditions>
          <action type="Rewrite" url="contact.asp"/>
        </rule>            
      </rules>
    </rewrite>

微软的 IIS 网站上有一个很好的教程:

https://www.iis.net/learn/extensions/url-rewrite-module/creating-rewrite-rules-for-the-url-rewrite-module

【讨论】:

    猜你喜欢
    • 2015-07-13
    • 2012-07-31
    • 2011-02-14
    • 2012-12-12
    • 2022-07-26
    • 1970-01-01
    • 2020-03-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多