2013-09-11 3 views
2

Я реализую переписывание URL-адресов в моем проекте. Я добавил правила перезаписи из IIS с помощью URL Rewrite. Ниже приведен код моего файла web.config, в котором добавляется правило:Удаление расширения .aspx из URL с использованием URL-адреса Перезапись

<system.webServer> 
     <modules runAllManagedModulesForAllRequests="true" /> 
     <rewrite> 
      <rules> 
       <rule name="URLRedirect" stopProcessing="true"> 
        <match url="^([a-z0-9/]+).aspx$" /> 
        <action type="Redirect" url="{R:1}" /> 
       </rule> 
      </rules> 
     </rewrite> 
    </system.webServer> 

Но проблема я написал правила для удаления только расширение т.е. .aspx и я хочу, чтобы мой URL выглядеть

http://localhost:58370/URLRedirect/Default. 

Но теперь она отображает его как http://localhost:58370/URLRedirect/ Как эта проблема может быть решена .....

ответ

6

Наконец я смог решить мою проблему удаления расширений .aspx из моих файлов. Я хотел, чтобы мой URL выглядеть следующим образом: http://localhost:58370/ShowPage вместо http://localhost:58370/ShowPage.aspx

1) Я добавил ShowPage.aspx страницу в папке с именем SHOWPAGE. 2) И следующие правила, которые я добавил в свой файл web.config:

<rewrite> 
      <rules> 
      <clear /> 
      <rule name="Redirect to clean URL" enabled="true" stopProcessing="true"> 
       <match url="^([a-z0-9/]+).aspx$" ignoreCase="true" /> 
       <conditions logicalGrouping="MatchAll" trackAllCaptures="false" /> 
       <action type="Redirect" url="{R:1}" /> 
      </rule> 
      <rule name="RewriteASPX" enabled="true"> 
       <match url="(.*)" /> 
       <conditions logicalGrouping="MatchAll" trackAllCaptures="false"> 
       <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
       <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
       </conditions> 
       <action type="Rewrite" url="{R:1}.aspx" /> 
      </rule> 
      </rules> 
     </rewrite> 
Смежные вопросы