URLリダイレクタ

PHP
URL

2chで、外部サイトへのURLリンクで使っているime.nuサービスみたいなのを書いてみた。

使い方
https://matsu.teraren.com/link/www.yahoo.co.jp
https://matsu.teraren.com/link/http://www.yahoo.co.jp

リンク元をさらしたくないときにはどうぞ。

ソースコード

index.php

<?php
// path prefix
$prefix = '/~matsu/link/';

$url = substr($_SERVER["REQUEST_URI"], strlen($prefix));
// add protocol if protocol is not specified
if(strpos($url, 'http') === false){
  $url = 'http://'.$url;
}

$url = htmlspecialchars($url);

?>
<html>
<head>
<title>jump</title>
</head>
<body>

<a href="<?php print $url; ?>"><?php print $url; ?></a><br />
別のサイトにジャンプしようとしています。宜しければ上記のリンクをクリックしてください
</p>
</body>
</html>


.htaccess

<ifmodule mod_rewrite.c>;
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /~matsu/link/index.php [L]
</ifmodule>

コメント