IIS URL重写规则重定向与掩码?

编程入门 行业动态 更新时间:2024-10-25 14:24:54
本文介绍了IIS URL重写规则重定向与掩码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有这样的网址:

http: //www.example/erf4d

(其中erf4d可以是任意5个字符的字符串)

(where erf4d can be any 5 character string)

我想将用户重定向到:

www.example/viewentry.aspx?ID=erf4d

我使用网上的重写规则完成了这项工作.config然而我希望它能够 www.example/erf4d停留在URL栏中,以便用户看不到丑陋的viewentry.aspx?ID = erf4d是一种重定向掩码,如果你愿意的话。无论如何要实现这个目标吗?

I have accomplished this using rewrite rules in web.config however I would like it so that www.example/erf4d stays in the URL bar such that the user dosen't see the "ugly" viewentry.aspx?ID=erf4d a sort of redirect mask if you will. Is there anyway to accomplish this?

推荐答案

根据我的经验,URL重写是反过来使用的。所以页面实际上是viewentry.aspx?ID = 123,重定向会将其重定向到/ 123。

In my experience URL rewrite is used the other way around. So the page is actually viewentry.aspx?ID=123 and the redirect will redirect it to /123.

我认为你可能做错了吗?如果您使用IIS 7中的向导为SEO友好URL设置URL重写并使用viewentry.aspx?ID = erf4d作为基础,它应该可以帮助您到达所需的位置。

I think you may be doing it the wrong way around? If you setup a URL Rewrite using the Wizard in IIS 7 for the SEO friendly URLs and use viewentry.aspx?ID=erf4d as a base, it should help get you where you need.

重定向/重写工作,所以如果你转到test/123它会工作,但如果你转到test/view.aspx?ID=123,它会发送给你test/ 123。我认为你追求的是什么?

The redirect / rewrites work, so that if you goto test/123 it will work, but if you goto test/view.aspx?ID=123, it'll send you to test/123. Which is what I think you're after?

干杯

编辑:以下是我使用的一个例子。它将读取news.aspx?page = 1并重写为news / 1 /。但由于规则的原因,news / 1 /实际上也有效,所以如果需要,可以在锚点中引用。

Here's an example of something I use. It will read news.aspx?page=1 and rewrite to news/1/. But due to the rules, news/1/ actually works as well, so can be refered that way in anchors if need be.

<rule name="Redirect - /news.aspx?page=a to /news/a/" enabled="true" stopProcessing="true"> <match url="^news\.aspx$" /> <conditions logicalGrouping="MatchAll" trackAllCaptures="false"> <add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" /> <add input="{QUERY_STRING}" pattern="^page=([0-9]{1,3})$" /> </conditions> <action type="Redirect" url="news/{C:1}" appendQueryString="false" /> </rule> <rule name="Rewrite - /news/a/ to page=a" enabled="true" stopProcessing="true"> <match url="^news/([^/]+)/?$" /> <conditions logicalGrouping="MatchAll" trackAllCaptures="false"> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> </conditions> <action type="Rewrite" url="news.aspx?page={R:1}" /> </rule>

更多推荐

IIS URL重写规则重定向与掩码?

本文发布于:2023-11-01 23:02:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1550662.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重写   掩码   重定向   规则   IIS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!