ASP.Net WebForm and IIS rewrite rule for adding co

2019-09-08 18:04发布

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

1条回答
啃猪蹄的小仙女
2楼-- · 2019-09-08 18:08

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.

查看更多
登录 后发表回答