Last active
July 1, 2016 11:48
-
-
Save kas-cor/271fe181b5101916959b to your computer and use it in GitHub Desktop.
Redirect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Options All -ExecCGI -Indexes -Includes +FollowSymLinks | |
ErrorDocument 404 /error404.html | |
RewriteEngine on | |
RewriteBase / | |
RewriteCond %{REQUEST_FILENAME} !-f | |
RewriteCond %{REQUEST_FILENAME} !-d | |
RewriteRule ^error404(.*).html$ /404.php?desc=$1 [L,QSA] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
header("HTTP/1.1 404 Not Found"); | |
define("DOMEN", "domen.com"); | |
define("EMAIL", "[email protected]"); | |
?><!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8" /> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" /> | |
<title>Страница не найдена (404)</title> | |
<link href="/css/style.min.css" rel="stylesheet" type="text/css" /> | |
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries --> | |
<!-- WARNING: Respond.js doesn't work if you view the page via file:// --> | |
<!--[if lt IE 9]> | |
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script> | |
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script> | |
<![endif]--> | |
</head> | |
<body> | |
<div class="container"> | |
<h2>Страница не найдена<br /><small>Ошибка 404</small></h2> | |
<h3><b>Вы искали:</b> <?= $_SERVER['HTTP_REFERER'] ?><br /><small><?= $_GET['desc'] ?></small></h3> | |
<div> | |
<a href="mailto:<?= EMAIL ?>?subject=error404&body=<?= $_SERVER['HTTP_REFERER'] ?>#<?= $_GET['desc'] ?>">Сообщить администратору</a> | |
</div> | |
<script type="text/javascript"> | |
var GOOG_FIXURL_LANG = "ru"; | |
var GOOG_FIXURL_SITE = "http://<?= DOMEN ?>"; | |
</script> | |
<script type="text/javascript" src="http://linkhelp.clients.google.com/tbproxy/lh/wm/fixurl.js"></script> | |
<ul><li>Перейти на главную <a href="/">страницу</a></li></ul> | |
<script type="text/javascript"> | |
document.querySelector("#goog-wm-qt").value = "<?= $_SERVER['HTTP_REFERER'] ?>".replace("http://<?= DOMEN ?>/", "").replace(".html", ""); | |
</script> | |
</div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @author kas-cor <[email protected]> | |
* @link http://github.com/kas-cor repositories | |
*/ | |
namespace cls; | |
class Redirect { | |
/** | |
* Debug mode | |
* @var bool | |
*/ | |
static $debug = FALSE; | |
/** | |
* Soft redirect JS | |
* @param string $url | |
*/ | |
static function soft($url = "") { | |
$url = "https://" . DOMEN . "/" . $url; | |
if (self::$debug) { | |
echo "Redirect (soft) to <a href=\"" . $url . "\">" . $url . "</a>"; | |
} else { | |
echo "<script type=\"text/javascript\">\n\twindow.location.href=\"" . $url . "\";\n</script>\n"; | |
} | |
exit(); | |
} | |
/** | |
* Hard redirect HTTP | |
* @param string $url | |
*/ | |
static function hard($url = "") { | |
$url = "https://" . DOMEN . "/" . $url; | |
if (self::$debug) { | |
echo "Redirect (hard) to <a href=\"" . $url . "\">" . $url . "</a>"; | |
} else { | |
header("location: " . $url); | |
} | |
exit(); | |
} | |
/** | |
* Redirect 404 (hard) | |
* @param string $info | |
*/ | |
static function error404($info = "") { | |
self::hard("error404" . (!empty($info) ? "-" . $info : "") . ".html"); | |
} | |
/** | |
* Redirect 404 (soft) | |
* @param string $info | |
*/ | |
static function error404soft($info = "") { | |
self::soft("error404" . (!empty($info) ? "-" . $info : "") . ".html"); | |
} | |
/** | |
* Redirect 301 | |
* @param string $url | |
*/ | |
static function on301($url = "") { | |
header("HTTP/1.1 301 Moved Permanently"); | |
self::hard($url); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Useing
Hard redirect
Soft redirect
Hard redirect 404
Soft redirect 404
Hard redirect 301