2014-07-20 4 views
0

완전히 nginx에 익숙하지 않습니다.URL이 nginx.conf에 IIS의 web.config에 다시 작성됩니다.

어떻게이 URL을 nginx로 다시 작성 하시겠습니까?

<rewrite> 
    <rules> 
     <rule name="IndexFolders" stopProcessing="true"> 
      <match url="(.*[^/]+)$" /> 
      <conditions> 
       <add input="{REQUEST_FILENAME}" matchType="IsDirectory" /> 
      </conditions> 
      <action type="Rewrite" url="/_index/{R:1}.html" /> 
     </rule> 
     <rule name="OtherFile" stopProcessing="true"> 
      <match url="\.\w+$" /> 
     </rule> 
     <rule name="HtmlFile" stopProcessing="true"> 
      <match url="^([^.]*[^/]+)$" /> 
      <action type="Rewrite" url="{R:1}.html" /> 
     </rule> 
    </rules> 
</rewrite> 

변환기를 시도했지만 작동하지 않습니다.

이 내 테스트 환경에서 작동
location/{ 
    if (-d $request_filename){ 
     set $rule_0 1; 
    } 
    if ($rule_0 = "1"){ 
     rewrite /(.*[^/]+)$ /_index/$1.html last; 
    } 
    location ~* /\.\w+$ { 
     break; 
    } 
    rewrite ^/([^.]*[^/]+)$ /$1.html last; 
} 
+1

대신'rewrite /? ([^ /] +) $'를 사용해보세요. – hjpotter92

+0

@ hjpotter92 당신은 무엇을 의미합니까? 작동하지 않고 500 개의 오류가 발생했습니다. –

+1

'location ~ * /\.\w+$ {break; }'는'if ($ uri ~ * \. \ w + $) {break; }','break'는''location/{}'에 다른 재 작성 규칙을 실행하는 것을 멈추게 할 것임을 의미합니다. – xiaochen

답변

1

:

location/{ 
    if (-d $request_filename){ 
     rewrite ^/(.*[^/]+)/$ /_index/$1.html break; 
    } 

    location ~* /.*\.\w+$ { 
     break; 
    } 

    rewrite ^/([^.]*[^/]+)$ /$1.html break; 
}    

공지 사항의 nginx rewrite directive :

마지막

:

옵션 플래그 매개 변수 중 하나가 될 수 있습니다

은 현재 ngx_http_rewrite_module 지시문 집합 처리를 중지하고 변경된 URI와 일치하는 새 위치를 검색합니다.

브레이크 브레이크 지시자로서 ngx_http_rewrite_module 지시어의 현재 세트를 처리

정지; 당신이 rewrited URL 규칙을 일치시키기위한 다음 루프에서 검색되는 원하지 않는 경우

그래서, 당신은 휴식를 사용해야합니다.

break directive:

경유

는 ngx_http_rewrite_module 지시어의 현재 세트를 처리하는 단계를 포함한다.

지시문이 위치 내에 지정된 경우 요청의 추가 처리가이 위치에서 계속됩니다.

URL Rewriter 동작과 비슷

:

규칙은 StopProcessing 플래그가 켜져있을 수 있습니다. 이 플래그가 켜지면 후속 규칙이 더 이상 처리되지 않고이 규칙에 의해 생성 된 URL이 IIS 요청 파이프 라인에 전달됩니다 (규칙이 일치하는 경우). 기본적으로이 플래그는 해제되어 있습니다.

관련 문제