【问题标题】:How do i hide page name in web.config with xml?如何使用 xml 在 web.config 中隐藏页面名称?
【发布时间】: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=([^=&amp;]+)$" />
                    </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=([^=&amp;]+)$" />
                    <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


【解决方案1】:

根据你的描述,我建议你可以试试下面的url重写规则。

您可以先将网址从www.website.com/page.php?user=text 重定向到www.website.com/text,然后您可以将www.website.com/text 重写为/page.php?user=text

规则如下:

            <rule name="Re1" stopProcessing="true">
                <match url="page.php" />
                <conditions>
                    <add input="{QUERY_STRING}" pattern="user=([^/]+)$" />
                </conditions>
                <action type="Redirect" url="http://localhost:9082/text" appendQueryString="false" />
            </rule>
            <rule name="RE2">
                <match url="([a-zA-Z0-9]+)$" />
                <action type="Rewrite" url="/page.php?user={R:0}" appendQueryString="false" />
            </rule>

【讨论】:

  • 这将无法正常工作,“user=text”中的文本部分是基于数据库选择的动态
  • 您的意思是查询字符串中的文本也会发生变化。这个查询字符串会包含多个键吗?
  • 多个键?我不知道。解释它的最简单方法是考虑 facebook 个人资料,例如 facebook.com/username 的 url 后面是 facebook.com/profile.php?id=stringofnumbers |我试图做到这一点,所以当我点击我网站上的用户个人资料时,它会隐藏页面名称等,只显示等号后的文本(作为所述人的用户名)
猜你喜欢
  • 2011-05-06
  • 1970-01-01
  • 2014-04-30
  • 2022-11-25
  • 2011-06-24
  • 1970-01-01
  • 2012-09-08
  • 1970-01-01
  • 2022-06-11
相关资源
最近更新 更多