如何构建网页

如何构建网页

问题描述:

当网站上的页面的结构如此时,背后的技术是什么? 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

+1

https://en.wikipedia.org/wiki/Front_controller – ceejayoz

+1

他们最有可能使用一些一种路由引擎。那里有很多,并且不可能仅仅从那个URL中知道。例如微软已经用ASP.Net MVC实现它们,Java有Spring MVC。 PHP有codeigniter(和其他人) – mituw16

+1

https://www.google.com/search?q=seo+folder+OR+URL+structure – mplungjan

您'重新使用经典的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(两个文件都位于根目录中),那么您可以将以下内容添加到<system.webServer>部分你的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