Skip to content

Instantly share code, notes, and snippets.

@aktaumag
Created March 12, 2020 08:13
Show Gist options
  • Save aktaumag/cd3b7f71fc588166725dd9850ff5b15c to your computer and use it in GitHub Desktop.
Save aktaumag/cd3b7f71fc588166725dd9850ff5b15c to your computer and use it in GitHub Desktop.
Основные перенаправления и прочие настройки в файле .htaccess
@aktaumag
Copy link
Author

aktaumag commented Mar 12, 2020

Перенаправление на страницу без index.php

БИТРИКС

<?php
// START WebSEO.kz Michael Nossov:
	$wscanonical = 'https://' . $_SERVER['HTTP_HOST'] . str_replace('index.php', '', $APPLICATION->GetCurPage(true));
	if(isset($_REQUEST['PAGEN_1']) && !empty($_REQUEST['PAGEN_1']) && intval($_REQUEST['PAGEN_1']) > 1){
		$wscanonical .= '?PAGEN_1='.intval($_REQUEST['PAGEN_1']);
	}
    // Перенаправление на страницу без index.php
	$ws_uri_parts = explode('?', $_SERVER['REQUEST_URI'], 2);
	if(substr($ws_uri_parts[0], -10) == '/index.php'){
		header("HTTP/1.1 301 Moved Permanently");
		header("Location: ".$wscanonical);
		exit();
	}
// END WebSEO.kz
?>

ДРУГОЕ

// Перенаправление на страницу без index.php
$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];
if(substr($ws_uri_parts[0], -10) == '/index.php'){
	header("HTTP/1.1 301 Moved Permanently");
	header("Location: ".$ws_uri_canonical );
	exit();
}

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