반응형
HTTPS 강제 리다이렉트가 Wordpress에서 작동하지 않음
내 Wordpress 디렉토리는 www.example.com/blog에 있습니다.
최근에 사이트 전체를 HTTPS로 변경했습니다.따라서 /blog/의 .htaccess 파일은 다음과 같습니다.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
또한 Wordpress 설정에서 사이트 URL을 HTTPS로 변경하였습니다.
이것은 홈페이지에서 완벽하게 동작하지만, 어떤 포스트 페이지에서도 최종 사용자는 URL을 변경하고 Enter 키를 눌러 비시큐어 HTTP로 변경할 수 있습니다.
예를 들어 직접 http://www.example.com/blog/post-1/ 라고 입력하면 HTTP 로딩됩니다.
.htaccess 파일에 무슨 문제가 있나요?미해결은 어디에 있습니까?
규칙의 순서를 변경합니다.첫 번째 리다이렉트httpsWP가 당신의 모든 요청을 넘겨받도록 하겠습니다.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
이 두 행을 wp-config에 추가할 수도 있습니다.php
define('WP_SITEURL', 'https://' . $_SERVER['HTTP_HOST']);
define('WP_HOME', 'https://' . $_SERVER['HTTP_HOST']);
따라서 개발 환경의 경우 http, 라이브 환경의 경우 https 조건을 쉽게 만들 수 있습니다.
if(strpos($_SERVER['HTTP_HOST'], 'livedomain.com') !== FALSE){
define('WP_SITEURL', 'https://' . $_SERVER['HTTP_HOST']);
define('WP_HOME', 'https://' . $_SERVER['HTTP_HOST']);
} else {
define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST']);
define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST']);
}
언급URL : https://stackoverflow.com/questions/19168489/https-force-redirect-not-working-in-wordpress
반응형
'programing' 카테고리의 다른 글
| Angularjs: 여러 $resource URL/데이터 소스를 제공하는 서비스? (0) | 2023.03.31 |
|---|---|
| 도커: Apple Silicon M1의 Apache (0) | 2023.03.31 |
| 스프링 부트는 데이터를 사용하여 데이터베이스를 초기화하기 위해 데이터를 로드하지 않습니다.sql (0) | 2023.03.26 |
| 누가 내 워드프레스 사이트를 호스팅하고 있는지 어떻게 알 수 있습니까? (0) | 2023.03.26 |
| TypeError: $.ajax(...)는 함수가 아닙니다. (0) | 2023.03.26 |