htaccess를 사용하여 하나의 하위 디렉토리를 제외한 모든 리디렉션 방법

StackOverflow https://stackoverflow.com/questions/925913

  •  06-09-2019
  •  | 
  •  

문제

.htaccess를 엉망으로 만든 지 오래되었습니다. example.com/* example.com/collector.html로 리디렉션 할 사이트가 있습니다. 제외하고 Subdirectory example.com/special의 URL의 경우 계속 작업하고 싶습니다.

예를 들어:

  • example.com/page.html example.com/collector.html로 리디렉션해야합니다
  • example.com/foo/bar는 example.com/collector.html로 리디렉션해야합니다
  • example.com/special/page.html은 리디렉션되지 않아야합니다

나는 그런 생각을했을 것입니다

RedirectMatch 302 ^/[^(special)]/.* /collector.html
RedirectMatch 302 ^/[^(collector.html)/]* /collector.html

트릭을 수행 할 것이지만, 내가 원하는 방식으로 작동하지 않는 것 같습니다.

도움이 되었습니까?

해결책

어쩌면 이건? (Mod_rewrite 필요)

RewriteEngine On
RewriteRule !^(special(/.*)?|collector\.html)$ collector.html [R,L]

다른 팁

이것은 당신이 설명한 디렉토리 구조를 재현 한 Apache 2.2.13에서 나에게 잘 작동합니다.

RedirectMatch 302 /(?!special)  http://www.example.com/collector.html

괄호 안의 패턴은 URI에 문자열 '특수'가 포함되어 있으면 일치하지 않습니다.

또한 모드 재 작성이 항상 사용할 수있는 것은 아니며이 경우 필요하지 않습니다.

이 시도:

RedirectMatch 302 /\/[^(special)]\/.+/ /collector.html 
RedirectMatch 302 /\/[^(collector\.html)]/ /collector.html

아마도...?

RewriteEngine on
RewriteRule ^(?!special) collector.html [R,NC]
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top