如何为URL进行URL重写以隐藏filename.aspx和querystring? [英] How to do URL rewriting for the URL to hide filename.aspx and querystring?

查看:70
本文介绍了如何为URL进行URL重写以隐藏filename.aspx和querystring?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

https://mysite.com/Admin/Dashboard/DashboardReport.aspx -这是我的实际网址,我想使用任何查询字符串值来隐藏filename.aspx.怎么样?

https://mysite.com/Admin/Dashboard/DashboardReport.aspx - this is my actual URL i want to hide the filename.aspx with if any querystring values. how?

我也在IIS中的URL重写中尝试过FriendlyURL.它不会生效.

also i have tried FriendlyURL in URL rewriting in IIS. it doesn't take effect.

请给我快速答复.

推荐答案

URL重写有点模棱两可.您是否正在重写用户看到的内容?还是服务器看到的是什么?最好相信您无法更改URL向网站使用者显示的内容.

URL Rewriting is somewhat ambiguous. Are you rewriting what the user sees? Or what the server sees? It's better to believe that you are not able to alter what the URL displays to the website consumer.

但是,诀窍是将它们发送到损坏的,非真实的URL ...然后为您重新编写URL,这样您就知道那个非真实的URL意味着什么.例如:

However, the trick is to send them to a broken, not-real URL... then ReWrite the URL for YOU, so you know what that not-real URL means. For example:

假设您有一个真实的URL,如下所示:

Imagine you have a Real URL like so:

http://www.example.com/folder/subfolder/page.ext?param=value

但是您想要重写" URL,使其看起来像这样:

But you want to "Rewrite" the URL to look like so:

http://www.example.com/subfolder/value

如果它们在页面 page.ext ... 上,则您无法更改其在URL栏中看到的内容.但是,您可以像这样将它们重定向到伪路径/subfolder/value :

If they are on the page page.ext..., you cannot change what they see in their URL bar. But, you can Redirect Them to a fake path /subfolder/value like so:

<rule name="subFolder Value Redirect">
  <conditions>
    <add input="{REQUEST_URI}" pattern="^/folder/([^/]+)/page\.ext\?param=([^&]+)$" />
  </conditions>
  <action type="Redirect" url="/{C:1}/{C:2}" />
</rule>

以上,我没有进行"URL匹配",因为我仅取决于条件.我唯一的条件是Request_URI看起来完全符合我的期望.一些文件夹,一些子文件夹名称,page.ext,以及带有param = SomeValue的查询字符串.我使用()括号来动态捕获子文件夹名称和参数值.

Above, I am not doing a "url match" because I am depending solely on a Condition. My only Condition is that the Request_URI looks exactly like I expect. Some folder, some subfolder name, page.ext, and a querystring with param=SomeValue. I use () parenthesis to dynamically capture the Subfolder Name and the param Value.

注意:{C:0}表示条件的第0个"捕获组.捕获0是正则表达式 ^/folder/([[^/] +)/page \ .ext \?param =([^&] +)$ 的整个结果.捕获1是第一个捕获组,即子文件夹名称.捕获2是第二个捕获组,即参数值.

Note: {C:0} means the "0th" Capture Group of the Conditions. Capture 0 is the Entire Result of the regex ^/folder/([^/]+)/page\.ext\?param=([^&]+)$. Capture 1 is the First Capture Group, the Subfolder Name. Capture 2 is the second Capture Group, the param Value.

^ 表示从头开始".有时,您不想从头开始,也不会在那里.

^ at the beginning of a regex means "starting from the beginning". Sometimes you don't want to start at the beginning and that wouldn't be there.

$ 表示末尾结束".有时,您不想在结尾处结束,也不会在那里结束.

$ at the end of a regex means "ending at the end". Sometimes you don't want to end at the end and that wouldn't be there.

字符类 [^ ...] 表示捕获不是 ... 的任何字符.在这种情况下,请捕获不包含斜线的所有内容或不包含与"号的所有内容.

The Character Class [^...] means to capture any character that is not .... In this case, capture anything that is not a Slash, or anything that is not an Ampersand.

重复运算符 [...] + Plus-Symbol意味着至少捕获一次,但最多捕获多次前面的规则.

The repetition operator [...]+ Plus-Symbol means to capture the preceding rule at least once, but up to many times.

.是一个特殊字符,表示任何内容".但是我们将其表示为扩展名 page.ext 中的点.因此您可以像 \.

. is a special character which means "anything". But we mean it as in the dot of an extension page.ext. So you escape it like \.

{REQUEST_URI} 意味着将您的模式与域/端口后的整个URL进行比较.因此,在URL http://www.example.com:1234/subfolder ... 中,/subfolder和以下所有内容位于{REQUEST_URI} EXCEPT 主题标签路由中.因此,如果您有Anchor或Angular UI Route,则它们仅留在浏览器中,并且始终位于任何重定向的末尾,但是服务器将永远看不到它们,因此您无法解析标签.

{REQUEST_URI} means to compare your pattern against the entire URL after the Domain/Port. So in the URL http://www.example.com:1234/subfolder... The /subfolder and all following contents are in the {REQUEST_URI} EXCEPT hashtag routing. So if you have an Anchor or Angular UI Route, those stay with the browser only, and will always be at the end of any redirect, but the server will never see them, so you can't parse off of hashtags.

操作类型=重定向" 仅表示此操作是将用户重定向到给定的URL.

action type="Redirect" just means this action is to redirect the user to a given URL.

url ="/{C:1}/{C:2}" 是相对于域的URL,因为它不是以协议开头的.这将重定向到/subFolder/value,因为在我们的模式中,条件捕获1和条件捕获2捕获了这两个值.

url="/{C:1}/{C:2}" is the URL relative to the domain, since it doesn't start with a protocol. This will redirect to /subFolder/value, because Condition capture 1 and Condition capture 2 in our pattern capture those two values.

插入此规则后,用户将被重定向到一个看起来像状态代表URL(RESTful)的残缺的弯曲URL.是的!

After inserting this rule, a user will be redirected to a broken janked up URL that looks like a State-Representative URL (RESTful). Yaay!!

重写是给您(服务器)的,而不是给客户的.但是现在,它们已被重定向到一个漂亮的断开URL,您可以找到该URL的上下文,并通过为服务器重写它来告诉服务器它的真正含义.

The rewrite is for you (the server), not for the customer. But now that they are redirected to a nice pretty broken URL, you can find the context of that URL and tell your server what it REALLY means by rewriting it for the server.

<rule name="subFolder Value Rewrite">
  <conditions><add input="{REQUEST_URI}" pattern="^/([^/]+)/([a-zA-Z0-9]+)$" /></conditions>
  <action type="Rewrite" url="/folder/{C:1}/page.ext?param={C:2}" />
</rule>

这几乎与先前规则相反.这将找到一种模式,其中存在一个路径"subFolder"名称,斜杠以及一个由字母和数字组成的值.它还再次描述了Begginning ^ 和End $ ,因为我们不希望出现意想不到的怪异事物.因此,这将捕获如下网址:

This is pretty much the inverse of the prior rule. This finds a pattern where there is a path "subFolder" name, slash, and a value made up of letters and numbers. It also, once again, describes the Begginning ^ and End $, because we don't expect unexpected weird things. So, this will catch a URL like:

http://www.example.com/subFolder/1234abcDE

但不会抓到

http://www.example.com/lol/somethingelse/15?blah=kthx

然后,重写URL评估为真实的真实URL,该URL映射到用于处理实际存在的文件的路径.并且,请记住,重写"意味着它将获取用户看到的不正确"假值,并将其重写回服务器的丑陋正确"值.并非如此.

The rewrite URL then evaluates back to a true real URL that maps to a path for processing for a file that really exists. And, keep in mind, that "rewrite" means it takes the "incorrect" fake value that the user sees, and rewrites it back to an ugly "correct" value for the server. Not the other way around.

这篇关于如何为URL进行URL重写以隐藏filename.aspx和querystring?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆