코드

http ---> https 301 redirect

상석하대 2023. 7. 21. 13:49

Rewrite 모듈, URL 재작성, https 설정 등이 돼 있는 상태에서다.

 

❚ .htaccess

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{HTTPS} off
  RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>

❚ nginx.conf

(server 블록 안)

	location / {
	  return 301 https://example.com$request_uri;
	}

❚ web.config

<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="HTTP to HTTPs Redirect" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{HTTPS}" pattern="^OFF$"  ignoreCase="true" />
                    </conditions>
                    <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType=""Permanent" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

❚ web.xml

<security-constraint>
    <web-resource-collection>
        <web-resource-name>HTTPS Forward All WEB APP</web-resource-name>
        <url-pattern>/*</url-pattern>
    </web-resource-collection>
    <user-data-constraint>
        <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    </user-data-constraint>
</security-constraint>
반응형