2017-10-28 6 views
0

webconfig에 규칙을 다시 쓰고 리디렉션하도록했습니다. 난 파일 확장명을 제거하고 URL 끝에 슬래시를 강제로 추가합니다. 코드가 있지만 파일 확장자를 숨겨서 같은 코드를 시도하면 파일 확장명과 함께 작동하지만 404 페이지로 이동합니다. 참고 - http://example.com/about-us.php/web.config : 파일 확장명을 숨기고 URL 끝에 슬래시를 추가합니다.

예상 결과를 작동하고는 - http://example.com/about-us/ 404 페이지로 리디렉션합니다.

web.config 파일을 사용하여 파일 확장명을 숨기고 후행 슬래시를 추가하는 코드를 알려주십시오.

내가 후행 슬래시가 추가, 나는 아래의 몇 가지 규칙을 적용했습니다하지만 난 그냥 참고로

브라우저

http://example.com/about-us를 넣어 입력 할 때이 http://example.com/about-us.php/에 저를 소요 - 그것은 http://example.com/about-us/으로 잘 작동하지만, 나는 http://example.com/about-us URL http://example.com/about-us/

여기

내 규칙 목록입니다 원하는 :

,
<system.webServer> 
    <httpErrors errorMode="Custom"><!-- For non-managed files --> 
     <remove statusCode="404" subStatusCode="-1" /> 
     <error statusCode="404" path="/404.php" responseMode="ExecuteURL" /> 
    </httpErrors> 
<rewrite> 
    <rules> 

     <rule name="Add trailing slash rule 1" stopProcessing="true"> 
      <match url="(.*[^/])$" /> 
      <conditions> 
      <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
      <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
      </conditions> 
      <action type="Redirect" redirectType="Permanent" url="{R:1}.php/" /> 
     </rule> 
     <rule name="Add trailing slash rule 2" stopProcessing="true"> 
      <match url="(.*[^/])" /> 
      <conditions> 
      <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
      <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
      </conditions> 
      <action type="Rewrite" url="{R:1}.php/" redirectType="Permanent" /> 
     </rule> 
     <rule name="hide php extension" stopProcessing="true"> 
      <match url="^(.*)$" /> 
      <conditions logicalGrouping="MatchAll"> 
       <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" /> 
       <add input="{REQUEST_FILENAME}.php" matchType="IsFile" ignoreCase="false" /> 
      </conditions> 
      <action type="Rewrite" url="{R:1}.php/" /> 
     </rule> 
    </rules> 
</rewrite> 
</system.webServer> 
+1

당신은 당신이 뭘하려합니다, 규칙을 추가시겠습니까? –

답변

1

이 규칙을 사용해야합니다

<rules> 
    <rule name="AddTrailingSlashRule" stopProcessing="true"> 
     <match url="(.*[^/])$" /> 
     <conditions> 
      <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
      <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
     </conditions> 
     <action type="Redirect" url="{R:1}/" /> 
    </rule> 

    <rule name="hide php extension" stopProcessing="true"> 
     <match url="^(.*)/$" /> 
     <conditions logicalGrouping="MatchAll"> 
      <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" /> 
     </conditions> 
     <action type="Rewrite" url="{R:1}.php" /> 
    </rule> 
</rules> 
+0

그것은 나를 위해 작동합니다. 감사합니다. – Sachin