문제

로드의 다른 페이지로 리디렉션하기 위해 기본 HTML 페이지를 설정할 수 있습니까?

도움이 되었습니까?

해결책

사용해보십시오 :

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

참고 : 헤드 섹션에 놓습니다.

이전 브라우저의 경우 빠른 링크를 추가하면 올바르게 새로 고치지 않는 경우에도 다음과 같습니다.

<p><a href="http://example.com/">Redirect</a></p>

로 나타납니다

리디렉션

이렇게하면 여전히 추가 클릭으로가는 곳으로 갈 수 있습니다.

다른 팁

나는 둘 다 사용할 것입니다 메타, 그리고 자바 스크립트 코드 만일을 대비하여 링크가있을 것입니다.

<!DOCTYPE HTML>
<html lang="en-US">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="refresh" content="0; url=http://example.com">
        <script type="text/javascript">
            window.location.href = "http://example.com"
        </script>
        <title>Page Redirection</title>
    </head>
    <body>
        <!-- Note: don't tell people to `click` the link, just tell them that it is a link. -->
        If you are not redirected automatically, follow this <a href='http://example.com'>link to example</a>.
    </body>
</html>

완전성을 위해 가능한 한 가장 좋은 방법은 서버 리디렉션을 사용하는 것이므로 301 상태 코드. 이것은 쉽게 수행 할 수 있습니다 .htaccess 사용하는 파일 아파치, 또는 수많은 플러그인을 통해 WordPress. 모든 주요 컨텐츠 관리 시스템에 대한 플러그인도 있다고 확신합니다. 또한 CPANEL은 서버에 설치된 경우 301 리디렉션에 대한 매우 쉽게 구성됩니다.

자바 스크립트

<script type="text/javascript">
    window.location.href = "http://example.com";
</script>

메타 태그

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

나는 할 것이다 또한 당신을 돕기 위해 표준 링크를 추가하십시오 사람들:

<link rel="canonical" href="http://www.example.com/product.php?item=swedish-fish"/>

이것은 모든 이전 답변과 .htaccess를 통한 HTTP 새로 고침 헤더를 사용한 추가 솔루션의 요약입니다.

1. HTTP 새로 고침 헤더

우선, .htaccess를 사용하여 이와 같은 새로 고침 헤더를 설정할 수 있습니다.

Header set Refresh "3"

이것은 사용과 동등한 "정적"입니다. header() 기능 PHP

header("refresh: 3;");

이 솔루션은 모든 브라우저에서 지원되는 것은 아닙니다.

2. JavaScript

대체로 URL:

<script>
    setTimeout(function(){location.href="http://example.com/alternate_url.html"} , 3000);
</script>

대체 URL없이 :

<script>
    setTimeout("location.reload(true);",timeoutPeriod);
</script>

jQuery를 통해 :

<script>
    window.location.reload(true);
</script>

3. 메타 새로 고침

JavaScript 및 리디렉션 헤더에 대한 종속성이 원치 않는 경우 메타 새로 고침을 사용할 수 있습니다.

대체 URL과 함께 :

<meta http-equiv="Refresh" content="3; url=http://example.com/alternate_url.html">

대체 URL없이 :

<meta http-equiv="Refresh" content="3">

사용 <noscript>:

<noscript>
    <meta http-equiv="refresh" content="3" />
</noscript>

선택적으로

Billy Moon이 추천 한대로 문제가 발생할 경우 새로 고침 링크를 제공 할 수 있습니다.

자동으로 리디렉션되지 않은 경우 : <a href='http://example.com/alternat_url.html'>Click here</a>

자원

헤드 내부 사이에 배치 된 다음 메타 태그는 브라우저에 리디렉션을 알려줍니다.

<meta http-equiv="Refresh" content="seconds; url=URL"> 

리디렉션하기 전에 2 초를 대기 할 수있는 수로 교체하고 URL을 리디렉션하려는 URL로 교체하십시오.

또는 JavaScript로 리디렉션 할 수 있습니다. 페이지의 어느 곳에도 스크립트 태그 내부에 배치하십시오.

window.location = "URL"

a를 설정하는 것이 좋습니다 301 리디렉션. Google의 웹 마스터 도구 기사를 참조하십시오 301 리디렉션.

최신 웹 표준을 따르기를 기대하는 경우 일반 HTML 메타 리디렉션을 피해야합니다. 서버 측 코드를 만들 수 없으면 선택해야합니다. 자바 스크립트 리디렉션 대신에.

JavaScript 기능 브라우저를 지원하려면 HTML 메타 리디렉션 라인을 noscript 요소. 그만큼 noscript 중첩 메타 리디렉션과 결합되었습니다 canonical 태그는 검색 엔진 순위에도 도움이됩니다.

리디렉션 루프를 피하려면 사용해야합니다. location.replace() 자바 스크립트 기능.

적절한 클라이언트 측 URL 리디렉션 코드는 다음과 같습니다 (인터넷 익스플로러 8 이하 고정 수정 및 지연없이) :

<!-- Pleace this snippet right after opening the head tag to make it work properly -->

<!-- This code is licensed under GNU GPL v3 -->
<!-- You are allowed to freely copy, distribute and use this code, but removing author credit is strictly prohibited -->
<!-- Generated by http://insider.zone/tools/client-side-url-redirect-generator/ -->

<!-- REDIRECTING STARTS -->
<link rel="canonical" href="https://stackoverflow.com/"/>
<noscript>
    <meta http-equiv="refresh" content="0; URL=https://stackoverflow.com/">
</noscript>
<!--[if lt IE 9]><script type="text/javascript">var IE_fix=true;</script><![endif]-->
<script type="text/javascript">
    var url = "https://stackoverflow.com/";
    if(typeof IE_fix != "undefined") // IE8 and lower fix to pass the http referer
    {
        document.write("redirecting..."); // Don't remove this line or appendChild() will fail because it is called before document.onload to make the redirect as fast as possible. Nobody will see this text, it is only a tech fix.
        var referLink = document.createElement("a");
        referLink.href = url;
        document.body.appendChild(referLink);
        referLink.click();
    }
    else { window.location.replace(url); } // All other browsers
</script>
<!-- Credit goes to http://insider.zone/ -->
<!-- REDIRECTING ENDS -->

당신은 a를 사용할 수 있습니다 메타 "리디렉션":

<meta http-equiv="refresh" content="0; url=http://new.example.com/address" />

또는 자바 스크립트 리디렉션 (모든 사용자가 JavaScript를 활성화 한 것은 아니므로 항상 백업 솔루션을 준비합니다).

<script language="javascript">
  window.location = "http://new.example.com/address";
</script>

그러나 나는 차라리 사용하는 것이 좋습니다 mod_rewrite, 옵션이있는 경우.

페이지가로드 되 자마자 init 함수가 발사되고 페이지가 리디렉션됩니다.

<!DOCTYPE html>
<html>
    <head>
        <title>Example</title>
        <script>
            function init()
            {
               window.location.href = "www.wherever.com";
            }
        </script>
    </head>

    <body onload="init()">
    </body>
</html>

다음 코드를 배치하십시오u003CHEAD> 그리고u003C/HEAD> HTML 코드의 태그 :

<meta HTTP-EQUIV="REFRESH" content="0; url=http://example.com/index.html">

위의 HTML 리디렉션 코드는 방문자를 다른 웹 페이지로 즉시 리디렉션합니다. 그만큼 content="0; 브라우저가 리디렉션하기 전에 대기 할 수있는 초 수로 변경 될 수 있습니다.

다음 코드를 <head> 부분:

<meta http-equiv="refresh" content="0; url=http://address/">

나는 a와 함께 일하는 동안 문제를 발견했다 JQuery Mobile 어떤 경우에는 내 메타 헤더 태그가 올바르게 리디렉션을 달성하지 못하는 응용 프로그램 (jQuery mobile은 각 페이지마다 헤더를 자동으로 읽지 않으므로 JavaScript를 복잡하게 래핑하지 않는 한 비효율적입니다). 이 경우 가장 쉬운 솔루션은 JavaScript 리디렉션을 다음과 같이 문서 본문에 직접 배치하는 것이 었습니다.

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta http-equiv="refresh" content="0;url=myURL" />
    </head>

    <body>
        <p>You are not logged in!</p>
        <script language="javascript">
            window.location = "myURL";
        </script>
    </body>
</html>

이것은 나를 위해 모든 경우에 효과가있는 것 같습니다.

모든 유형의 페이지에 맞는 간단한 방법은 meta 머리에 태그 :

<html>
    <head>
        ...
        <meta HTTP-EQUIV="REFRESH" content="seconds; url=your.full.url/path/filename">
        ...
    </head>
    <body>
        Don't put much content, just some text and an anchor.
        Actually, you will be redirected in N seconds (as specified in content attribute).
        That's all.
        ...
    </body>
</html>

JavaScript를 사용해야합니다. 다음 코드를 헤드 태그에 배치하십시오.

<script type="text/javascript">
 window.location.assign("http://www.example.com")
</script>

HTTP 상태 코드 301 또는 302로 자동 리디렉션 할 수 있습니다.

php :

<?php
    Header("HTTP/1.1 301 Moved Permanently");
    Header("Location: http://www.redirect-url.com");
?>

좋은 측정을 위해 :

<?php
header("Location: example@example.com", TRUE, 303);
exit;
?>

스크립트 위에 에코가 없는지 확인하십시오. 그렇지 않으면 무시됩니다.http://php.net/manual/en/function.header.php

본체 태그의 온부하 이벤트 만 사용하십시오.

<body onload="window.location = 'http://example.com/'">

index.html에서 사용자를 리디렉션하는 스크립트를 사용합니다. 상대적인 로그인 페이지의 URL

<html>
  <head>
    <title>index.html</title>
  </head>
  <body onload="document.getElementById('lnkhome').click();">
    <a href="/Pages/Login.aspx" id="lnkhome">Go to Login Page<a>
  </body>
</html>

면도기 엔진 5 초 지연 :

<meta http-equiv="Refresh"
         content="5; url=@Url.Action("Search", "Home", new { id = @Model.UniqueKey }))">
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Redirect to a page</title>
    </head>
    <body onload="window.location.assign('http://example.com')">

    </body>
</html>

이를 위해 JavaScript 코드가 필요하지 않습니다. 이것을 작성하십시오 <head> HTML 페이지의 섹션 :

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

페이지가 0 초로로드 되 자마자 페이지로 이동할 수 있습니다.

내가 이해하는 한,이 질문에 대해 지금까지 본 모든 방법은 오래된 위치를 역사에 추가하는 것처럼 보입니다. 페이지를 리디렉션하려면 역사상 기존 위치가 없으려면 replace 방법:

<script>
    window.location.replace("http://example.com");
</script>

이것은 내가 원했던 모든 것을 갖춘 리디렉션 솔루션이지만 잘라 내기 위해 깨끗한 스 니펫으로 찾을 수 없었습니다.

이 스 니펫에는 여러 가지 장점이 있습니다.

  • 사람들이 자신의 URL에 가지고있는 쿼리 스트링 매개 변수를 잡고 유지할 수 있습니다.
  • 원치 않는 캐싱을 피하기 위해 링크를 만들지 않습니다
  • 기존 및 새 사이트 이름을 사용자에게 알릴 수 있습니다.
  • 정착 가능한 카운트 다운을 보여줍니다
  • 매개 변수를 유지하므로 딥 링크 리디렉션에 사용할 수 있습니다

사용하는 방법:

전체 사이트를 마이그레이션 한 경우 이전 서버에서 원래 사이트를 중지하고 루트 폴더의 기본 index.html 파일 로이 파일을 사용하여 다른 사이트를 만듭니다. 404 오류 가이 index.html 페이지로 리디렉션되도록 사이트 설정을 편집하십시오. 이렇게하면 하위 레벨 페이지에 링크가있는 이전 사이트에 액세스하는 사람이 있습니다.

이제 오프닝 스크립트 태그로 이동하여 Oldsite 및 Newsite 웹 주소를 편집하고 필요에 따라 초 값을 변경하십시오.

웹 사이트를 저장하고 시작하십시오. 직업 완료 - 커피를위한 시간.

<!DOCTYPE html>
<html>
<head>
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
<META HTTP-EQUIV="EXPIRES" CONTENT="Mon, 22 Jul 2002 11:12:01 GMT">
<style>
body { margin: 200px; font: 12pt helvetica; }
</style>

</head>
<body>

</body>
<script type="text/javascript">

// Edit these to suit your needs.
var oldsite = 'http://theoldsitename.com'
var newSite = "https://thenewsitename.com";
var seconds = 20;  // countdown delay.

var path = location.pathname;
var srch = location.search;
var uniq = Math.floor((Math.random() * 10000) + 1);
var newPath = newSite + path + (srch === '' ? "?" + uniq : srch + "&" + uniq); 


document.write ('<p>As part of hosting improvements, the system has been migrated from ' + oldsite + ' to</p>');
document.write ('<p><a href="' + newPath + '">' + newSite + '</a></p>');
document.write ('<p>Please take note of the new website address.</p>');
document.write ('<p>If you are not automatically redirected please click the link above to proceed.</p>');
document.write ('<p id="dvCountDown">You will be redirected after <span id = "lblCount"></span>&nbsp;seconds.</p>');

function DelayRedirect() {
    var dvCountDown = document.getElementById("dvCountDown");
    var lblCount = document.getElementById("lblCount");
    dvCountDown.style.display = "block";
    lblCount.innerHTML = seconds;
    setInterval(function () {
        seconds--;
        lblCount.innerHTML = seconds;
        if (seconds == 0) {
            dvCountDown.style.display = "none";
            window.location = newPath;
        }
    }, 1000);
}
DelayRedirect()

</script>
</html>

이 코드 사용 :

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

주의를 기울이십시오 : 헤드 태그에 넣으십시오.

JavaScript로 할 수 있습니다.

location = "url";
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top