[HTML5+CSS]網頁自動轉址的方法

方法一、 HTML 的轉址方法: 

在 HTML 網頁的 </head> 前加入以下 HMTL 碼,網頁就會自動轉址。 

<meta http-equiv="refresh" content="0;url=https://tech.digitgeek.net" />

其中 content=... 中的 0 是指 0 秒後自動重新整理,並轉址到 "https://tech.digitgeek.net" 這個網址。 


方法二、 Javascript 的轉址方法: 

在 HTML 網頁中原則上是任一地方加入以下 JavaScript 網頁就會轉址。但放在網頁 HTML 碼的開始較有效率(也較有意義)。 

<script>document.location.href="https://tech.digitgeek.net";</script>


方法三、 PHP 的轉址方法: 

<?php

    header('Location: https://tech.digitgeek.net');

    exit;

?>


方法四、 .htaccess

直接更改 .htaccess,這個檔案通常會在網站的根目錄。

在 .htaccess 中要這麼寫:

Redirect /old http://your_domain.com/new


如果有安裝 mod_rewrite 模組的話,也可以這樣寫:

RewriteEngine on

RewriteRule ^wordpress(.*)$ /blog$1 [R=301,L]


把 .htaccess 放到 舊網址 的根目錄,然後要這麼寫:

RewriteEngine on

RewriteRule (.*) http://new_domain.com/$1 [R=301,L]


0 條回復   |  直到 2019-3-3 | 2554 次瀏覽




熱門評論


登入後才可發表內容