Skip to content

Instantly share code, notes, and snippets.

@aktaumag
Last active March 16, 2022 12:46
Show Gist options
  • Save aktaumag/36c45babde04c1b3565cb607c78b8a3c to your computer and use it in GitHub Desktop.
Save aktaumag/36c45babde04c1b3565cb607c78b8a3c to your computer and use it in GitHub Desktop.
$ws_uri_parts = explode('?', $_SERVER['REQUEST_URI'], 2);
$ws_uri_protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
$ws_uri_canonical = $ws_uri_protocol . $_SERVER['HTTP_HOST'] . $ws_uri_parts[0];
@aktaumag
Copy link
Author

aktaumag commented Feb 1, 2019

WebaSyst

В админке находим шаблон и в файле index.html добавляем перед стандартным выводом тега небольшую модификацию

    {$trimmed_absolute_url = $wa->currentUrl(true, true)}
    {if empty($canonical)}
        {if $wa->get('page', 1) > 1}
            {$canonical_http = $wa->currentUrl(true)}
        {else}
            {$canonical_http = $trimmed_absolute_url}
        {/if}
    {else}
        {$canonical_http = $canonical}
    {/if}
    {if !empty($canonical_http)}
        {$canonical = $canonical_http|regex_replace:'/^http:\/\//':'https://'}
    {/if}

    {if !empty($canonical)}
        <link rel="canonical" href="{$canonical}"/>
    {/if}

@aktaumag
Copy link
Author

aktaumag commented Jan 20, 2020

// Перенаправление на страницу без index.php
$ws_uri_parts = explode('?', $_SERVER['REQUEST_URI'], 2);
if(substr($ws_uri_parts[0], -10) == '/index.php'){
header($_SERVER['SERVER_PROTOCOL'] . " 301 Moved Permanently");
header("Location: ".$wscanonical);
exit();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment