ASP.Net WebForm和IIS重写规则,用于在所有URL中添加国家/地区代码 [英] ASP.Net WebForm and IIS rewrite rule for adding country code in all url
问题描述
我有一个关于网址重写的小问题。假设我想在我的所有网址中添加国家/地区代码,请访问www.mysite.com/gb/home.aspx或www.mysite.com/de/home.aspx,但是当上述类型时,将没有名为gb或de的文件夹将发出url然后我需要在内部将请求发送到我的root home.aspx文件,国家/地区代码将作为查询字符串传递。如何使用IIS重写规则实现此目的。我想我们需要用iis重写规则处理它,但我不知道iis重写规则对于这种情况会是什么样子。如果有人知道那么可以共享我需要在web.config文件中编写的iis重写规则的代码。
请帮我处理我需要在web.config文件中编写的示例iis重写规则。
谢谢
如果您使用的是重写模块,请点击这些说明可以帮助你。
我不是正则表达式的专家,但我想你最终会在web配置中使用类似这样的重写规则:
< rule name =重写语言代码>
< match url =^([a-z] +)/([0-9a-z] +)。aspx/>
< action type =Rewriteurl =/ {R:2} .aspx?lang = {R:1}/>
< / rule>
如果您只想匹配两个字符的语言代码,那么您可能会调整第一个匹配小组这样做。
sorry posting this kind of code without any effort because i have no basic idea handling this situation with iis rewrite rule. i have seen people handle this with iis rewrite rule but i am not aware what to write in web.config file for iis rewrite rule.
I have one small question regarding url rewrite. suppose i want to add country code in my all url say www.mysite.com/gb/home.aspx or www.mysite.com/de/home.aspx but there will be no folder called gb or de rather when the above kind of url will be issued then i need to internally send the request to my root home.aspx file and country code will be passed as query string. how can i achieve this with IIS rewrite rule. i guess we need to handle it with iis rewrite rule but i do not know how iis rewrite rule would look like for this scenario. if anyone know then can share the code for iis rewrite rule which i need to write in web.config file.
please help me with sample iis rewrite rule which i need to write in web.config file. thanks
If you are using the rewrite module, then following these instructions should help you.
I am no expert with regular expressions, but I imagine you will end up with a rewrite rule in the web config similar to something like this:
<rule name="Rewrite language code">
<match url="^([a-z]+)/([0-9a-z]+).aspx" />
<action type="Rewrite" url="/{R:2}.aspx?lang={R:1}" />
</rule>
If you want to match only on a two character language code, then you could likely adjust the first match group to do so.
这篇关于ASP.Net WebForm和IIS重写规则,用于在所有URL中添加国家/地区代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!