IIS URL Rewrite ASP

前端 未结 2 592
北恋
北恋 2020-12-06 23:20

I do my best to scan the forum for help to make a web.config to do a Rewrite of this kind of url

domain.com/default.asp?id=3&language=2

2条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-07 00:13

    If you want to use regular expressions you could do something like this

    
         
             
                 
                 
             
         
    
    

    This would rewrite "domain.com/en/service" as "domain.com/default.asp?language=en&id=Service", or "domain.com/2/3" as "domain.com/default.asp?language=2&id=3"

    To change the 2 to en and the 3 to service, along with all the other options though I think you would need a separate rule for each permutation, or have some sort of logic within your asp pages to read your querystring variables and send the corresponding values to your SQL queries. Note also that the parameters in the friendly url appear in the same order and the querystring variables in the rewritten URL, although this shouldn't really be an issue. If someone tries to access the page with the original "unfriendly" url they will find what they are looking for, whichever way round they enter the querystring variables.

    Please note, I didn't actually hand code the rule above, I generated it with the URL Rewrite module in IIS manager - it makes life a lot easier

    Also note, as discussed with my namesake in the other answer, this only applies to IIS7 and above

提交回复
热议问题