<?php Header("HTTP/1.1 301 Moved Permanently"); Header("Location: http://www.redirect-url.com"); ?>
核心代码
结合Meta标签和JavaScript的重定向示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
<!DOCTYPE HTML> <htmllang="en-US"> <head> <metacharset="UTF-8"> <metahttp-equiv="refresh"content="0; url=http://example.com"> <scripttype="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 <ahref='http://example.com'>link to example</a>. </body> </html>
<!DOCTYPE html> <html> <head> <METAHTTP-EQUIV="CACHE-CONTROL"CONTENT="NO-CACHE"> <METAHTTP-EQUIV="PRAGMA"CONTENT="NO-CACHE"> <METAHTTP-EQUIV="EXPIRES"CONTENT="Mon, 22 Jul 2002 11:12:01 GMT"> <style> body { margin: 200px; font: 12pt helvetica; } </style> </head> <body> <scripttype="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> seconds.</p>');