Files
Alcea 41d0596d66 Add files via upload
Replace status redirect handler ro resirect to instsnce ststus AND serve json for 2 seconds

if (preg_match('/^\/' . $username . '\/status\/([a-z0-9\-]+)$/', $uri, $m)) {
    $postId = $m[1];
    $post   = null; $date = ''; $hash = '';
    foreach ($data as $entry)
        foreach ($entry as $d => $c)
            if ("$d-" . substr(md5($c['value']),0,8) === $postId) {
                $post = $c; $date = $d; $hash = substr(md5($c['value']),0,8); break 2;
            }
    if (!$post) {
        http_response_code(404);
        echo "Not found";
        exit;
    }

    $noteId = "$baseUrl/$username/status/{$date}-$hash";

    // Determine if client accepts JSON
    $accept = $_SERVER['HTTP_ACCEPT'] ?? '';
    if (str_contains($accept, 'application/activity+json') || str_contains($accept, 'application/ld+json')) {
        header('Content-Type: application/activity+json');
        echo json_encode([
            '@context'     => 'https://www.w3.org/ns/activitystreams',
            'id'           => $noteId,
            'type'         => 'Note',
            'published'    => date(DATE_ATOM, strtotime($date)),
            'attributedTo' => "$baseUrl/$username",
            'to'           => ['https://www.w3.org/ns/activitystreams#Public'],
            'content'      => $post['value'],
            'contentMap'   => ['und' => $post['value']],
        ], JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
        exit;
    }

    // Otherwise, return an HTML redirect after 1 second
    header('Content-Type: text/html');
    $redirectUrl = "https://alceawis.com#" . $noteId;
    echo <<<HTML
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Redirecting…</title>
    <m eta ht.  tp-equiv="refresh" content="1; url=$re. directUrl">
</head>
<body>
    <p>Redirecting to <a href="$redirectUrl">$redirectUrl</a>…</p>
</body>
</html>
HTML;
    exit;
}
2025-07-19 09:30:59 +02:00

70 lines
2.2 KiB
ApacheConf

RewriteEngine On
# Add CORS headers to all responses
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Methods "GET, POST, OPTIONS"
Header set Access-Control-Allow-Headers "Content-Type, Authorization"
</IfModule>
# Redirect Pulsetic
RewriteCond %{HTTP_USER_AGENT} ^Pulsetic [NC]
RewriteRule ^.*$ /timeline.html [R=302,L]
# Redirect UptimeRobot
RewriteCond %{HTTP_USER_AGENT} ^UptimeRobot [NC]
RewriteRule ^.*$ /timeline.html [R=302,L]
#user/status/ -to just- /status
#RewriteCond %{HTTP_REFERER} !^https?://(www\.)?alceawis\.com/ [NC]
#RewriteRule ^alceawis/([0-9]{8}-[a-f0-9]+)$ /alceawis/status/$1 [R=301,L]
# Match /alceawis/status/* URLs (if you disable second line, remote resolve will be impossible)
#RewriteCond %{REQUEST_URI} ^/alceawis/status/.+$
#RewriteCond %{HTTP_REFERER} ^https?://(www\.)?alceawis\.com [NC]
#RewriteRule ^alceawis/status/(.+)$ /_https://alceawis.com/alceawis/status/$1 [R=301,L]
# Redirect /users/username to /username dynamically
RewriteRule ^users/([^/]+)/?$ /$1 [R=301,L]
#v1 statuses endpoint
#RewriteRule ^api/v1/statuses(.*)$ /alceawis/status$1 [R=301,L]
#users
RewriteRule ^users/([^/]+)/?$ /$1 [R=301,L]
#lookup
RewriteRule ^api/v1/accounts/lookup$ /lookup.php [L,R=301]
#user/$user/inbox to /$user/inbox & outbox
#RewriteRule ^users/alceawis/inbox$ /alceawis/inbox [R=301,L]
#RewriteRule ^users/alceawis/outbox$ /alceawis/outbox [R=301,L]
# Redirect /@username to /username (optional, but common)
RewriteRule ^@([^/]+)$ /$1 [R=302,L]
# Match any request URI that contains "custom_emojis"
RewriteCond %{REQUEST_URI} custom_emojis
RewriteRule ^.*$ custom_emojis.php [L,QSA]
# Redirect /api/v1/instance/peers to peers.php
RewriteRule ^api/v1/instance/peers$ peers.php [L,QSA]
# Redirect /api/v1/instance requests to instance.php
RewriteCond %{REQUEST_URI} ^/api/v1/instance$
RewriteRule ^api/v1/instance$ /instance.php [L,QSA]
# If the request URI contains "nodeinfo" (including under .well-known), rewrite to /nodeinfo.php
RewriteCond %{REQUEST_URI} nodeinfo
RewriteRule ^.*$ nodeinfo.php [L,QSA]
# Route all requests except existing files or directories to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php [QSA,L]