Skip to content
This repository was archived by the owner on Nov 18, 2025. It is now read-only.

Commit dcbdead

Browse files
committed
🔨 modify redirect function
1 parent 413401e commit dcbdead

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

framework/helpers/url_helper.php

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -514,8 +514,7 @@ function url_title($str, $separator = '-', $lowercase = FALSE)
514514

515515
// ------------------------------------------------------------------------
516516

517-
if ( ! function_exists('redirect'))
518-
{
517+
if ( ! function_exists('redirect')) {
519518
/**
520519
* Header Redirect
521520
*
@@ -531,39 +530,42 @@ function url_title($str, $separator = '-', $lowercase = FALSE)
531530
*/
532531
function redirect($uri = '', $method = 'auto', $code = NULL)
533532
{
534-
if ( ! preg_match('#^(\w+:)?//#i', $uri))
535-
{
533+
$raw_uri = $uri;
534+
535+
if (strstr($uri, '.')) {
536+
$uri = str_replace('.', '/', $uri);
537+
}
538+
539+
if (strstr($uri, 'http') !== false || strstr($uri, 'https') !== false) {
540+
$uri = $raw_uri;
541+
}
542+
543+
if (!preg_match('#^(\w+:)?//#i', $uri)) {
536544
$uri = site_url($uri);
537545
}
538546

539547
// IIS environment likely? Use 'refresh' for better compatibility
540-
if ($method === 'auto' && isset($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') !== FALSE)
541-
{
548+
if ($method === 'auto' && isset($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') !== FALSE) {
542549
$method = 'refresh';
543-
}
544-
elseif ($method !== 'refresh' && (empty($code) OR ! is_numeric($code)))
545-
{
546-
if (isset($_SERVER['SERVER_PROTOCOL'], $_SERVER['REQUEST_METHOD']) && $_SERVER['SERVER_PROTOCOL'] === 'HTTP/1.1')
547-
{
550+
} elseif ($method !== 'refresh' && (empty($code) or !is_numeric($code))) {
551+
if (isset($_SERVER['SERVER_PROTOCOL'], $_SERVER['REQUEST_METHOD']) && $_SERVER['SERVER_PROTOCOL'] === 'HTTP/1.1') {
548552
$code = ($_SERVER['REQUEST_METHOD'] !== 'GET')
549553
? 303 // reference: http://en.wikipedia.org/wiki/Post/Redirect/Get
550554
: 307;
551-
}
552-
else
553-
{
555+
} else {
554556
$code = 302;
555557
}
556558
}
557559

558-
switch ($method)
559-
{
560+
switch ($method) {
560561
case 'refresh':
561-
header('Refresh:0;url='.$uri);
562+
header('Refresh:0;url=' . $uri);
562563
break;
563564
default:
564-
header('Location: '.$uri, TRUE, $code);
565+
header('Location: ' . $uri, TRUE, $code);
565566
break;
566567
}
567568
exit;
568569
}
569570
}
571+

0 commit comments

Comments
 (0)