Remove multiple forward slashes

前端 未结 3 1922
遥遥无期
遥遥无期 2021-01-12 19:33

I\'ve noticed that with .NET MVC sites, you\'re able to hit URLs with multiple forward slashes, for example:

http://www.example.com//category
http://www.exam         


        
3条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-12 20:05

    URL Rewrite Module

    As IIS automatically normalizes url's with double slashes, you can try to redirect to the normalized url like this:

    
      
        
          
          
          
            
          
        
      
    
    

    You can also try to disable caching of the URL rewrite module:

    Disabling internal caching of rewrite rules

    To disable caching of inbound rewrite rules in URL Rewrite Module run the following command from an elevated command prompt:

    reg add HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\InetStp\Rewrite /v RewriteCacheEnabled /t REG_DWORD /d 0

    I have a small feeling that you'll have to restart the webserver after this change :)

    Other option #1: non-cacheable server variable

    This idea just popped into my mind:

    use a non-cacheable server variable in the rule, f.e. try with HTTP_USER_AGENT

    
      
        
          
          
          
            
            
          
        
      
    
    

    You can explore other server variables here

    Other option #2: clear browser cache

    During web development, make sure you use Ctrl+F5 to refresh your page, or clear your browser cache after making changes like updating rewrite rules etc. Otherwise you can spend hours of watching to the same problem while it was just your browser that needed to refresh its cache.

    Other option #3: IIRF

    If you really can't get it to work with the IIS URL Rewrite Module, you can give the open-source ISAPI module IIRF a try. It accepts rules similar to mod_rewrite for Apache.

提交回复
热议问题