2011-09-06 14 views
22

Używam tego kodu w web.config w jednym z folderów mojej witryny, aby przekierować wszystkie strony do katalogu głównego, ponieważ chcę zamknąć tę sekcję na stałe.ASP.NET httpRedirect: przekierowuję wszystkie strony z wyjątkiem jednego

<?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> 

Ale muszę zrobić wyjątek od tej zasady: Nie chcę, aby moja strona "default.aspx" była przekierowaniem. Jak mogę to zrobić?

Odpowiedz

12

można dodać wieloznacznego w następujący sposób, aby przekierować tylko niektóre pliki:

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

ale nie jestem pewien, czy można negować, że tak, że ignoruje pewien plik.

34

Umieść Default.aspx jako <location> z wyłączonym httpRedirect. Nie ma znaczenia, czy wstawisz <location> przed lub po <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> 
Powiązane problemy