我目前正在使用IIS7的网址重写模块,但使用IIS7的网址重写模块的主要漏洞是,我必须为所有页面编写规则,我想在网站上使用它,我想使用逗号规则将其重定向到特定的页面(比如主页),并使用global.asax将其重定向到所需的页面……
有没有可能用url重写,或者有没有什么工具可以用来做这件事,或者有一个代码样本可以帮助我做到这一点。
我不想在网址中扩展。
我有像index.aspx,news.aspx,artists.aspx,lessons.aspx这样的页面...我想要的网址像索引,新闻,课程,艺术家,我在web.config中创建了一个规则,就像
< rewrite>
< rules>
< rule name="urlType1">
< match url="^(\w*)" />
< action type="Rewrite" url="default.aspx" appendQueryString="false" />
< /rule>
< /rules>
< /rewrite> 这会将任何页面放到default.aspx,然后在global.asax中使用rawUrl,我会检查页面,就像用户输入“default.aspx”然后重写到news.aspx一样
希望这能有所帮助。
发布于 2011-08-17 13:59:27
您可以按照问题中的建议进行操作--将所有请求重定向到单个URL:然后在Global.asax中,您可以调用Server.Transfer( "~/file1.aspx“)将请求转发到特定的文件。
或者,您可以直接从URL重写规则进行传输,并跳过在Global.asax文件中的进一步处理。例如,此规则将读取没有文件扩展名的传入URL,然后将请求转发到具有文件扩展名的文件:
<rule name="Append a file extension to all requests discard querystring" stopProcessing="true">
<match url="^(.*)\?" />
<action type="Rewrite" url="{R:1}.aspx" />
</rule>在Ruslan Yakushev的博客http://ruslany.net/上阅读更多关于URL重写规则的内容。
发布于 2011-06-09 02:25:48
编辑for,所以就我所知,你需要为每个页面创建一个特定的重写规则asking...as。我更多的是沿着MVC的思路思考,当你去到哪里:
/news
它会路由到
/default.aspx
它调用NewsController.Index并显示来自default.aspx的新闻页面。然而,据我所知,要真正将所有内容分解到单独的页面中并尝试删除extension...as,您必须为每个实例创建一个新规则。
可以从web.config文件配置重定向规则。
例如,下面是WordPress在WordPress附带的web.config文件中所做的事情:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="wordpress" patternSyntax="Wildcard">
<match url="*"/>
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
</conditions>
<action type="Rewrite" url="index.php"/>
</rule></rules>
</rewrite>
</system.webServer>
</configuration>将所有流量路由到index.php页面。然后,index.php文件读取该URL并根据该URL输出数据。它不会在重定向后将其重定向到不同的页面,而是决定要显示的内容。
MVC的工作原理是这样的,你可以看到这个url:
/news > will call > NewsController.Index();
/news/index > will call > NewsController.Index();
/news/view > will call > NewsController.View();
/news/read/id > will call > NewsController.Read(id);然后,这些控制器通常从数据库中获取数据,并将数据应用到“视图”(位于服务器上某处的html页面,该页面带有变量以显示控制器传递给它的数据)。
https://stackoverflow.com/questions/6283387
复制相似问题