【发布时间】:2020-01-23 06:00:32
【问题描述】:
我想知道是否有办法隐藏网站上的页面名称(在浏览器 URL 中)但仍使用 IIS web.config 文件显示获取请求?
假设站点名称是
www.website.com
带有(文件扩展名已隐藏)的页面
www.website.com/page.php
获取请求
www.website.com/page.php?user=text
其中“文本”是动态的
我希望它显示为
www.website.com/text
这是可能的吗?
我注意到一个类似的问题here,但即使将 asp 更改为 XML,该方法似乎也不起作用。
提前致谢!
编辑: 这是我尝试使用的 xml 代码(此特定代码不起作用)
<rule name="subFolderValueRedirect" enabled="true">
<conditions>
<add input="{REQUEST_URI}" pattern="^/page\.php?user=([^/]+)$" />
</conditions>
<action type="Redirect" url="/{C:2}" />
</rule>
<rule name="fileValueRewrite" enabled="true">
<conditions>
<add input="{REQUEST_URI}" pattern="^/([^/]+)/([a-zA-Z0-9]+)$" /></conditions>
<action type="Rewrite" url="/page.php?user={C:2}" />
</rule>
编辑 2: 这是我的 IIS 吐出的内容;但它会为我抛出错误 500
入站规则 -
<rule name="RedirectUserFriendlyURL1" stopProcessing="true">
<match url="^page$" />
<conditions>
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
<add input="{QUERY_STRING}" pattern="^user=([^=&]+)$" />
</conditions>
<action type="Redirect" url="{C:1}" appendQueryString="false" />
</rule>
<rule name="RewriteUserFriendlyURL1" stopProcessing="true">
<match url="^([^/]+)/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="page?user={R:1}" />
</rule>
出站规则
<outboundRules>
<rule name="OutboundRewriteUserFriendlyURL1" preCondition="ResponseIsHtml1">
<match filterByTags="A, Form, Img" pattern="^(.*/)page\?user=([^=&]+)$" />
<action type="Rewrite" value="{R:1}{R:2}/" />
</rule>
<preConditions>
<preCondition name="ResponseIsHtml1">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
</preConditions>
</outboundRules>
【问题讨论】:
-
您是否使用了任何特定的框架/语言?
-
什么意思?该站点正在使用在 iis 上运行的 php,并且 web.config 文件使用 xml
-
我与 IIS 交互已经有一段时间了,但这个答案 stackoverflow.com/a/43352452/3783243 看起来是正确的。你能展示你尝试了什么以及发生了什么吗?此外,您使用的 IIS 版本也可能有用
-
这是我发布的同一个链接,这个方法不起作用。在它失败后,我查看了 {C:#} 方法,它看起来好像被 asp 使用(基于我的研究)并且不适用于 xml 但是当我将它更改为 {R:#} 我得到错误 500。我使用的是 IIS 版本 10。
标签: iis url-rewriting