Welcome Guest, Not a member yet? Register   Sign In
URL Rewriting with redirection
#1

[eluser]tzultacah[/eluser]
I was having an issue with URL rewriting with the "redirect" function. I am using the .htaccess modifications listed in the User Guide, which works great when redirection is not taking place.

What was happening was this: When I clicked on links the URL rewrite was working fine, but when I used the redirect('stuff/to_thing') function, index.php was getting back into my URL. So I created a helper file "My_url_helper.php" and over-rode the redirect function as follows:
Code:
function redirect($uri = '', $method = 'location', $http_response_code = 302) {
    switch($method)
    {
        case 'refresh'    : header("Refresh:0;url=".site_url($uri));
            break;
        default            : header("Location: ".preg_replace('#index.php\/#', '', site_url($uri)), TRUE, $http_response_code);
            break;
    }
    exit;
}
This is the line of code that changed:
Code:
default            : header("Location: ".site_url($uri), TRUE, $http_response_code);
to:
Code:
default            : header("Location: ".preg_replace('#index.php\/#', '', site_url($uri)), TRUE, $http_response_code);
Very simple, and seems to address the issue I was having perfectly.
#2

[eluser]xwero[/eluser]
set the index_page in the config.php file to an empty string and you don't need to change the redirect function.
#3

[eluser]tzultacah[/eluser]
Ahhh.... good call! Thank you, I forgot all about that! ;-)




Theme © iAndrew 2016 - Forum software by © MyBB