조건부 .htaccess 리디렉션

조건부 .htaccess 리디렉션

이 주제에 대한 많은 질문과 답변이 있습니다. 하지만 난 아직도 갇혀 있어요!

.htaccess내 웹사이트에는 제대로 작동하고 모든 사람을 내 새 웹사이트의 홈페이지로 리디렉션하는 기본 기능이 있습니다 .

Options +FollowSymLinks 
RewriteEngine on 

RewriteCond %{HTTP_HOST} ^oldsite.com [OR] 
RewriteCond %{HTTP_HOST} ^www.oldsite.com [NC]

RewriteRule (.*) https://newsite.com [R=301,L]

하지만 이제는 다음을 기반으로 사용자를 "지능적으로" 리디렉션하려고 합니다.

IF {Page URL matches /services(.*)}
  THEN {Redirect users to http://newsite.com/solutions/}
ELSEIF {Page URL == /faq/faq1}
  THEN {Redirect users to https://newsite.com/faq/}
ELSE {Redirect users to https://newsite.com/} (root domain)

어떻게 하나요?

답변1

나는 당신이 모든 경우에 HTTPS로 리디렉션하기를 원한다고 가정합니다. 이는 http://단지 오타일 뿐입니다.

RewriteCond %{HTTP_HOST} ^oldsite.com [OR] 
RewriteCond %{HTTP_HOST} ^www.oldsite.com [NC]
RewriteRule ^/services https://newsite.com/solutions/ [R=301,L]

RewriteCond %{HTTP_HOST} ^oldsite.com [OR] 
RewriteCond %{HTTP_HOST} ^www.oldsite.com [NC]
RewriteRule ^/faq/faq1 https://newsite.com/faq/ [R=301,L]

RewriteCond %{HTTP_HOST} ^oldsite.com [OR] 
RewriteCond %{HTTP_HOST} ^www.oldsite.com [NC]
RewriteRule .* https://newsite.com/ [R=301,L]

관련 정보