코드

URL redirect

상석하대 2023. 7. 20. 19:40

❚ 메타태그

<meta http-equiv="refresh" content="0; url=https://example2.com">

❚ body 태그

<body onload="window.location='https://example2.com'">

❚ JavaScript

  if (window.location == 'https://example.com') {
    window.location.href='https://example2.com';
  }
  var url = 'example.com';
  var urlr = 'example2.com';
  var online = document.URL;
  if(online.match(url)) document.location.href = online.replace(url, urlr);

❚ IIS에 web.config

<configuration>
    <system.webServer> 
        <httpRedirect enabled="true" destination="https://example2.com">
    </system.webServer>
</configuration>

❚ .htaccess

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{HTTP_HOST} ^example.com [NC,OR]
  RewriteCond %{HTTP_HOST} ^www.example.com [NC]
  RewriteRule ^(.*)$ https://example2.com/$1 [L,R=301,NC]
</IfModule>

❚ nginx.conf

    location = / {
      return 301 https://example2.com;
    }

❚ PHP

<?
  sleep(5);
  header("Location: https://example2.com"); 
  exit;
?>

❚ ASP

<%
  response.redirect "https://example2.com" 
%>

❚ JSP

<% 
  response.sendRedirect("https://example2.com"); 
%>
반응형