2013-08-10 3 views
0
try_files $uri/index.html $uri @moved; 
    location @moved { 
    rewrite ^/categories/dogs-c-food/products/xyz-product$ /categories/dogs/food/products/xyz-product permanent; 
    rewrite ^/categories/dogs-c-leash/products/xyz-product$ /categories/dogs/leash/products/xyz-product permanent; 
    rewrite ^/categories/cats-c-litter-box/products/xyz-product$ /categories/cats/litter-box/products/xyz-product permanent; 
} 

하는 $ URI는 항상 시작하기 때문에,이의 nginx는

try_files $uri/index.html $uri @moved; 

location @moved { 
    rewrite ^/categories/(.+)-c-(.+)$ "/categories/$1/$2" permanent; 
} 

와 시도 그리고 슬래시에주의 해주십시오 /

+0

정확하게이 표현식이하는 것은 아닙니까? 뭐가 문제 야 ? – HamZa

+0

네, 작동합니다. 동적으로 만들고 싶습니다. – yokoho

+0

다시 작성하려는 일부 주소와 예상되는 결과가 반영되도록 질문을 편집 할 수 있습니까? – HamZa

답변

0

-c-을 한 줄 정규식을 사용하여 교체 할 정규 표현식으로 재 작성 슬래시 (/)를 사용하여 새로운 '이동 된'시나리오로 리디렉션 한 후에는 동일해야합니다.

+0

감사하지만 오류 로그에이 오류가 발생했습니다 : "^/categories/(+ *) - c - (+ *) $"("* *) - c - (+ *) $"에서 반복하지 않음 – yokoho

+0

죄송합니다. 수정 라인에 오타가 있습니다 (업데이트했습니다). 다음과 같이 사용하십시오.'다시 쓰십시오 ^/categories /(.+)-c-(. +) $ "/ categories/$ 1/$ 2 "영구적 인"- 이제 작동 할 것입니다. – surajs21