웹 사이트 리디렉션은 Firefox에서 간헐적으로 작동하지만 IE에서는 전혀 작동하지 않습니다. [중복]

Apr 04 2020

웹 사이트 리디렉션에서 오류를 몇 번 시도한 후 웹 사이트 리디렉션을 수행 할 수 있지만 Firefox에서는 간헐적으로 작동하지만 IE에서는 전혀 작동하지 않습니다. 모든 캐시를 지우고 Firefox에서 다시 시도하면 작동하지만 이상하게도 작동하지 않습니다. 그 당시 파일을 변경하지 않았 음을 확인했습니다. 누구든지 전에 이것을 생각했거나 직면 했습니까? 나는 2 분처럼 행복했지만 내 웹 사이트가 마침내 리디렉션되어 다시 리디렉션되지 않아서 기뻤습니다. : (( http://example.com 을 입력 할 때 리디렉션해야합니다. https://www.example.com으로 리디렉션됩니다. 아래는 .htaccess 파일의 리디렉션입니다.

RewriteEngine On
#Options +FollowSymLinks
RewriteCond %{HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} ^example\.com$[OR] RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule .* https://www.example.com%{REQUEST_URI} [R=301,L]

다음은 내 로그입니다.

init rewrite engine with requested uri /
pass through /
[perdir D:/wamp64/www/example/] strip per-dir prefix: D:/wamp64/www/example/ -> 
[perdir D:/wamp64/www/example/] applying pattern '.*' to uri ''
[perdir D:/wamp64/www/example/] RewriteCond: input='off' pattern='!on' => matched
[perdir D:/wamp64/www/example/] RewriteCond: input='www.example.com' pattern='^www\\.example\\.com$' => matched
[perdir D:/wamp64/www/example/] rewrite '' -> 'https://www.example.com/'
[perdir D:/wamp64/www/example/] explicitly forcing redirect with https://www.example.com/
[perdir D:/wamp64/www/example/] escaping https://www.example.com/ for redirect
[perdir D:/wamp64/www/example/] redirect to https://www.example.com/ [REDIRECT/301]

또한 내 웹 사이트는 VPN에서 로그 아웃 할 때만 리디렉션된다는 것을 발견했습니다 (리디렉션을 위해 수행 한 정보를 수정하거나 얻기 위해 서버에 연결할 수 있도록 VPN이 필요합니다).

아래는 .htaccess 파일에 추가 한 항목입니다.

    RewriteCond %{HTTPS} !on [OR]
    RewriteCond %{HTTP_HOST} ^example\.com$
    RewriteCond %{HTTP_HOST] ^www\.example\.com$
    RewriteRule .* https://www.example.com%{REQUEST_URI} [R=301,L]

아래는 내 httpd-vhosts.conf입니다.

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot "d:/wamp64/www/example"
    <Directory  "d:/wamp64/www/example/">
        Options +Indexes +Includes +FollowSymLinks +MultiViews
        AllowOverride All
        Order allow,deny
        Allow from all
        Header always set Strict-Transport-Security "max-age=63072000; includeSubDomains"
    </Directory>
</VirtualHost>

내 SSL 인증서는 httpd-ssl.conf에 구성되었으므로 httpd-vhosts.conf를 VirtualHost * : 80으로 지정합니다. 아래는 내 httpd-vhosts.conf입니다.

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot "d:/wamp64/www/example"
    <Directory  "d:/wamp64/www/example/">
        Options +Indexes +Includes +FollowSymLinks +MultiViews
        AllowOverride All
        Order allow,deny
        Allow from all
        Header always set Strict-Transport-Security "max-age=63072000; includeSubDomains"
    </Directory>
</VirtualHost>

최신 정보

다음은 [OR]을 추가하여 .htaccess에서 업데이트 한 내용입니다.

RewriteCond %{HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule .* https://www.example.com%{REQUEST_URI} [R=301,L]

그리고 내가 얻은 로그는 다음과 같습니다.

strip per-dir prefix: D:/wamp64/www/example/ -> 
applying pattern '.*' to uri ''
RewriteCond: input='off' pattern='!on' => matched
rewrite '' -> 'https://www.example.com/'
explicitly forcing redirect with https://www.example.com/
escaping https://www.example.com/ for redirect
redirect to https://www.example.com/ [REDIRECT/301]

브라우저에서 다시 시도했지만 리디렉션되지 않았습니다. 또한 firefox에서 디버깅하려고 시도하고 호스트는 example.com입니다.

이것은 [OR]을 제거하여 얻은 것입니다.

RewriteCond %{HTTPS} !on 
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule .* https://www.example.com%{REQUEST_URI} [R=301,L]

로그 :

RewriteCond: input='off' pattern='!on' => matched
RewriteCond: input='www.example.com' pattern='^example\\.com$' => not-matched

내가 몇 달 동안 일을 해왔고 지금은 생각에서 벗어나기 때문에 내 방향 전환이 작동하고 있다고 말 해주세요 (나는 바보 같은 실수 때문이 아니길 바랍니다 ...기도!). 저를 도와 주시고 미리 감사드립니다!

답변

3 EsaJokinen Apr 04 2020 at 16:56

나는 당신이 실제로이 조건을 원하지 않는다고 생각합니다.

RewriteCond %{HTTP_HOST} ^www\.example\.com$

그 자체로 무한 리디렉션 루프가 발생하기 때문에 버전 .htaccess에도 적용되는 것입니다 https://www.

RewriteRule .* https://www.example.com%{REQUEST_URI} [R=301,L]
2 liverwust Apr 04 2020 at 16:49

나는 그것이 누락 된 공백 문자라고 생각합니다. 이것을 변경하십시오 :

RewriteCond %{HTTP_HOST} ^example\.com$[OR]

이에:

RewriteCond %{HTTP_HOST} ^example\.com$ [OR]

귀하의 로그 파일 항목은 http://www.example.com 이 https://www.example.com/ 에 성공적으로 재 작성 되었음을 입증했습니다 . 그들은 http://example.com 에 대해 아무것도 증명하지 않았습니다 . 공백 문자를 추가하면 후자가 수정됩니다.

1 dexter Apr 04 2020 at 18:10

대신 mod_rewriteVirtualhost 정의에서 다음과 같은 것을 사용해야합니다.

ServerName  www.example.com
ServerAlias example.com
Redirect permanent / https://www.example.com/

Apache httpd 문서 에 따르면 .

mod_rewrite는 다른 대안이 필요한 경우 최후의 수단으로 간주되어야합니다. 더 간단한 대안이있을 때이를 사용하면 혼란스럽고 깨지기 쉬우 며 유지하기 어려운 구성으로 이어집니다.