![조건부 .htaccess 리디렉션](https://linux55.com/image/118311/%EC%A1%B0%EA%B1%B4%EB%B6%80%20.htaccess%20%EB%A6%AC%EB%94%94%EB%A0%89%EC%85%98.png)
이 주제에 대한 많은 질문과 답변이 있습니다. 하지만 난 아직도 갇혀 있어요!
.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]