.htaccess를 사용하여 HTTP를 HTTP로 리디렉션
173 개 이상의 찬성표가 있는 길고 상세한 스레드 를 추천하지 마세요 . 그것은 나를 위해 작동하지 않았습니다. 나는 또한 다른 많은 것을 시도했습니다 ( 1 , 2 , 3 , 4 ). 그들은 모두 나에게 TOO_MANY_REDIRECTS 또는 오류 500을 제공합니다. 그래서 여기 내 문제가 있습니다.
내 현재 .htaccess를 사용하면 다음과 같은 일이 발생합니다.
https://www.dukescasino.com/- 완벽하게 작동합니다.
https://dukescasino.com/- 위의 페이지로 리디렉션됩니다.
아래의 두 옵션은 정상적으로로드되지만 https 버전으로 리디렉션되어야합니다.
현재 .htaccess는 다음과 같습니다.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# BEGIN WordPress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
관련성이 있다고 생각하지 않지만 그렇다면 현재 활성화 된 플러그인 목록은 다음과 같습니다.
- 고급 사용자 정의 필드
- 올인원 SEO 팩
- 탐색 메뉴 용 Bop 검색 창 항목 유형
- 문의 양식 7
- 댓글 비활성화
- Google XML Sitemap
- WordPress.com의 Jetpack
- 검색 및 필터링
- 슬라이더 WD
- TablePress
- UpdraftPlus-백업 / 복원
- Wordfence 보안
- WPide
- WP 스 머시
- WP 슈퍼 캐시
편집 1-수행 된 테스트 :
테스트 A :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
# First rewrite to HTTPS:
# Don't put www. here. If it is already there it will be included, if not
# the subsequent rule will catch it.
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Now, rewrite any request to the wrong domain to use www.
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# BEGIN WordPress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
결과 : ERR_TOO_MANY_REDIRECTS
테스트 B :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
# BEGIN WordPress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
결과 : ERR_TOO_MANY_REDIRECTS
테스트 C :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
# BEGIN WordPress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
결과 : ERR_TOO_MANY_REDIRECTS
테스트 D :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# BEGIN WordPress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
결과 : ERR_TOO_MANY_REDIRECTS
테스트 E :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI}$1 [R=301,L]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI}$1
# BEGIN WordPress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
결과 : 302 개를 찾았습니다. 또한 ErrorDocument를 사용하여 요청을 처리하는 동안 500 내부 서버 오류 오류가 발생했습니다.
Dreamhost에서는 다음과 같이 작동했습니다.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# BEGIN WordPress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
문제 해결됨!
최종 .htaccess :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{ENV:HTTPS} !=on
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
# BEGIN WordPress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
나를 위해 작동합니다.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule ^(.*) https://%{SERVER_NAME}/$1 [R,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
필자의 경우 htaccess 파일에는 Far Future Expiration 및 WPSuperCache 와 같은 플러그인에 의해 설치된 많은 규칙 과 wordpress 자체의 줄이 포함되어 있습니다.
일을 엉망으로 만들지 않기 위해 솔루션을 htaccess의 맨 위에 두어야했습니다 (중요합니다. 마지막에 넣으면 캐시 플러그인과의 충돌로 인해 잘못된 리디렉션이 발생합니다)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
이렇게하면 일부 설정이 변경 될 때 워드 프레스로 인해 줄이 엉망이되지 않습니다. 또한 <IfModule>
문제없이 섹션을 반복 할 수 있습니다.
깔끔한 htaccess 규칙 에 대해 Jason Shah 에게 감사드립니다 .
귀하의 정보는 실제로 귀하의 호스팅 제공 업체에 달려 있습니다.
제 경우에는 ( Infomaniak ) 위의 어떤 것도 실제로 작동하지 않았고 무한 리디렉션 루프가 발생했습니다.
이를 수행하는 올바른 방법은 실제로 지원 사이트에 설명되어 있습니다 .
RewriteEngine on
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule (.*) https://your-domain.com/$1 [R=301,L]
따라서 항상 호스팅 제공 업체에 확인하십시오. 이 작업을 수행하는 방법을 설명하는 기사가 있기를 바랍니다. 그렇지 않으면 지원을 요청하십시오.
이것은 테스트를 거쳐 사용하기에 안전합니다.
왜? 때 워드 프레스 편집하여 다시 쓰기 규칙 , 그렇게 확신하여 만들 HTTPS 규칙을 제거해서는 안됩니다 ! 따라서 이것은 기본 Wordpress 규칙과 충돌하지 않습니다 .
<IfModule mod_rewrite.c>
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*) https://%{SERVER_NAME}/$1 [R,L]
</IfModule>
# BEGIN WordPress
<IfModule mod_rewrite.c>
#Your our Wordpress rewrite rules...
</IfModule>
# END WordPress
참고 : 당신은 변경해야 워드 프레스 주소 및 사이트 주소 에 URL을 https://
에서 일반 설정 (도 wp-admin/options-general.php
)
불행히도이 Q & A에 나열된 모든 솔루션이 저에게 적합하지 않음을 발견했습니다. 작업은 다음과 같습니다.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*\.php)$ $1 [L]
RewriteRule . index.php [L]
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^/?$ "https\:\/\/www\.example\.com\/" [R=301,L]
</IfModule>
# End Wordpress
위의 Wordpress 규칙은 다중 사용자 네트워크 모드의 Wordpress에 적용됩니다. Wordpress가 단일 사이트 모드 인 경우 다음을 사용합니다.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^/?$ "https\:\/\/www\.example\.com\/" [R=301,L]
</IfModule>
# End Wordpress
위의 어떤 것도 나를 위해 일하지 않았습니다. 그러나 그 라인은 내 WordPress 사이트에서 동일한 문제를 해결했습니다.
RewriteEngine On
RewriteCond %{HTTP:HTTPS} !on
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
http://example.com 에서 https://example.com으로 site_url 및 home을 수정하기 위해 wordpress 에서 http를 https로 리디렉션하는 가장 쉬운 방법 입니다. Wordpress가 리디렉션을 수행합니다. (이것이 "너무 많은 리디렉션"오류가 발생하는 이유입니다. 워드 프레스는 http로 리디렉션되고 .htaccess는 https로 리디렉션됩니다.)
편집하지 않으려는 경우 사용할 수있는 대체 솔루션은 다음과 같습니다 .htaccess
.
add_action( 'template_redirect', 'nonhttps_template_redirect', 1 );
function nonhttps_template_redirect() {
if ( is_ssl() ) {
if ( 0 === strpos( $_SERVER['REQUEST_URI'], 'https' ) ) {
wp_redirect( preg_replace( '|^http://|', 'https://', $_SERVER['REQUEST_URI'] ), 301 );
exit();
} else {
wp_redirect( 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 301 );
exit();
}
}
}
테마 하단에 배치 할 수 있습니다. functions.php
WordPress의 .htaccess 파일에 다음을 추가하십시오.
RewriteCond %{HTTP_HOST} ^yoursite.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.yoursite.com [NC]
RewriteRule ^(.*)$ https://www.yoursite.com/$1 [L,R=301,NC]
따라서 기본 WordPress의 .htaccess 파일은 다음과 같아야합니다.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTP_HOST} ^yoursite.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.yoursite.com [NC]
RewriteRule ^(.*)$ https://www.yoursite.com/$1 [L,R=301,NC]
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteEngine On
RewriteCond %{HTTP_HOST} ^digitalsoftwaremarket.com [NC]
RewriteRule ^(.*)$ http://www.digitalsoftwaremarket.com/$1 [L,R=301]
</IfModule>
The above final .htaccess and Test A,B,C,D,E did not work for me. I just used below 2 lines code and it works in my WordPress website:
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.thehotskills.com/$1 [R=301,L]
I'm not sure where I was making the mistake but this page helped me out.
None if this worked for me. First of all I had to look at my provider to see how they activate SSL in .htaccess
my provider gives
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP:HTTPS} !on
RewriteRule (.*) https://%{SERVER_NAME}/$1 [QSA,L,R=301]
</IfModule>
But what took me days of research is I had to add to wp-config.php
the following lines as my provided site is behind a proxy :
/**
* Force le SSL
*/
define('FORCE_SSL_ADMIN', true);
if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false) $_SERVER['HTTPS']='on';
Just add or replace this code in your .htaccess file in wordpress
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Redirect from http to https://www
RewriteEngine On RewriteCond %{HTTP_HOST} ^example\.com [NC] RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
This will work for sure!
Just add this code, And it will work like charm:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST}#%{HTTPS}s ^www\.([^#]+)#(?:off|on(s)) [NC]
RewriteRule ^ http%2://%1%{REQUEST_URI} [R=301,L]
</IfModule>
참고URL : https://stackoverflow.com/questions/32049820/use-htaccess-to-redirect-http-to-https
'Program Tip' 카테고리의 다른 글
Windows에서 모든 .svn 디렉토리를 재귀 적으로 제거하는 명령 (0) | 2020.10.22 |
---|---|
둥근 모서리가있는 Android에서보기를 만드는 방법 (0) | 2020.10.22 |
MVC 면도기 @foreach (0) | 2020.10.22 |
Docker의 개인 1.0 레지스트리에서 이미지를 검색하는 방법은 무엇입니까? (0) | 2020.10.22 |
ExecutorService를 통해 CompletionService를 언제 사용해야합니까? (0) | 2020.10.22 |