Redirect custom url with get method
In my encoder application / helper / MY_url_helper I would like to be able to add '?&route=' . $uri
I would like to be able to use my '?&route='
after index.php, but before the first folder / function.
But every time I click on the link the URL changes but the page stays the same?
Question: On my helper, how can I add '?&route=' . $uri
but make it still redirected to the page currently every time, even when I click the link, the url changes, but the page stays the same?
redirect('common/dashboard');
Url http://localhost/project/admin/?&route=common/dashboard
I tried it with routes and the same problem.
<?php
if ( ! function_exists('redirect'))
{
function redirect($uri = '', $method = 'auto', $code = NULL)
{
//if ( ! preg_match('#^(\w+:)?//#i', $uri))
//{
$uri = site_url('?&route=' . $uri);
//}
// IIS environment likely? Use 'refresh' for better compatibility
if ($method === 'auto' && isset($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') !== FALSE)
{
$method = 'refresh';
}
elseif ($method !== 'refresh' && (empty($code) OR ! is_numeric($code)))
{
if (isset($_SERVER['SERVER_PROTOCOL'], $_SERVER['REQUEST_METHOD']) && $_SERVER['SERVER_PROTOCOL'] === 'HTTP/1.1')
{
$code = ($_SERVER['REQUEST_METHOD'] !== 'GET')
? 303 // reference: http://en.wikipedia.org/wiki/Post/Redirect/Get
: 307;
}
else
{
$code = 302;
}
}
switch ($method)
{
case 'refresh':
header('Refresh:0;url='.$uri);
break;
default:
header('Location: '.$uri, TRUE, $code);
break;
}
exit;
}
}
.htaccess
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Update:
Codeigniter version using 3
In my configuration, I now use
Tried
$config['uri_protocol'] = 'REQUEST_URI';
and
$config['uri_protocol'] = 'QUERY_STRING';
But then now they say that the page was not found?
The page is there.
Also "shared" will be the folder
And the "dashboard" will be the controller
All controllers have first letter as uppercase Dashboard.php
Note. I tried to include query strings in config.php but doesn't work the way I am following it.
source to share
The first steps I had to take to solve the problem were
In routes.php
$get_route_method = 'route=';
$route[$get_route_method . 'common/dashboard'] = "common/dashboard/index";
Seems to work fine now when I manually added the route in application / config / route.php
Then in MY_url_helper in application / helper.php $uri = site_url('index.php?route=' . $uri);
<?php
if ( ! function_exists('redirect'))
{
function redirect($uri = '', $method = 'auto', $code = NULL)
{
if ( ! preg_match('#^(\w+:)?//#i', $uri))
{
$uri = site_url('index.php?route=' . $uri);
}
// IIS environment likely? Use 'refresh' for better compatibility
if ($method === 'auto' && isset($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') !== FALSE)
{
$method = 'refresh';
}
elseif ($method !== 'refresh' && (empty($code) OR ! is_numeric($code)))
{
if (isset($_SERVER['SERVER_PROTOCOL'], $_SERVER['REQUEST_METHOD']) && $_SERVER['SERVER_PROTOCOL'] === 'HTTP/1.1')
{
$code = ($_SERVER['REQUEST_METHOD'] !== 'GET')
? 303 // reference: http://en.wikipedia.org/wiki/Post/Redirect/Get
: 307;
}
else
{
$code = 302;
}
}
switch ($method)
{
case 'refresh':
header('Refresh:0;url='.$uri);
break;
default:
header('Location: '.$uri, TRUE, $code);
break;
}
exit;
}
}
source to share