2011-09-06 16 views
22

Io uso questo codice nel web.config in una delle cartelle del mio sito Web per reindirizzare tutte le pagine alla radice perché voglio chiudere definitivamente questa sezione.ASP.NET httpRedirect: reindirizza tutte le pagine tranne uno

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
<location> 
    <system.webServer> 
     <httpRedirect enabled="true" destination="http://www.example.com/" httpResponseStatus="Permanent" /> 
    </system.webServer> 
    </location> 
</configuration> 

ma ho bisogno di fare un'eccezione a questa regola: non voglio che la mia pagina "default.aspx" essere redirect. Come lo posso fare?

risposta

12

è possibile aggiungere un carattere jolly nel seguente modo, per reindirizzare solo determinati file:

<configuration> 
     <system.webServer> 
      <httpRedirect enabled="true" exactDestination="true" httpResponseStatus="Found"> 
      <add wildcard="*.php" destination="/default.htm" /> 
      </httpRedirect> 
     </system.webServer> 
    </configuration> 

ma non sono sicuro se si può negare che, in modo che ignora un determinato file.

34

Inserire il file Default.aspx come <location> con httpRedirect disattivato. Non importa se si inserisce <location> prima o dopo <system.webServer>.

<configuration> 
    <system.webServer> 
     <httpRedirect enabled="true" destination="http://www.example.com/" exactDestination="true" httpResponseStatus="Permanent" /> 
    </system.webServer> 
    <location path="Default.aspx"> 
     <system.webServer> 
      <httpRedirect enabled="false" /> 
     </system.webServer> 
    </location> 
</configuration> 
Problemi correlati