Redirect to fetch if there is an issue

This commit is contained in:
Kai Hendry
2015-10-02 14:33:55 +08:00
parent 0c95f8c595
commit d00917a424
3 changed files with 13 additions and 1 deletions

View File

@@ -19,13 +19,14 @@ http {
charset utf-8;
access_log /srv/http/u/greptweet.access.log;
error_log /srv/http/u/greptweet.error.log;
error_page 404 403 =303 /404.php;
location / {
index index.php index.html;
rewrite ^/f/(.*)$ /create.php?id=$1 last;
}
location ~ \.(svg|txt)$ {
location ~ \.(txt)$ {
add_header Content-Encoding gzip;
gzip off;
}

11
www/404.php Normal file
View File

@@ -0,0 +1,11 @@
<?php
if (preg_match('#^/u/#', $_SERVER["REQUEST_URI"])) {
$username = basename($_SERVER["REQUEST_URI"]);
if ((!empty($username)) && (strlen($username < 16)) && preg_match('/^[A-Za-z0-9_]+$/', $username)) {
header("Location:http://" . $_SERVER["HTTP_HOST"] . "/f/" . $username);
die();
}
}
?>
<img style="width: 20%;" src=/icons/greptweet_birdie.svg>
<h1>Error <?php echo $_SERVER["REQUEST_URI"]; ?></h1>