0

i spend many hours to solve my problem, but it won't work pls, help me, i'm working with it since the end of december (proove here: http://forum.php.pl/index.php?showtopic=225498&hl=)

i wanna to redirect users from my old page, based on pure php, without CI, to my new page based on CI

i've made yet rules to redirect static pages from old page, but i've problems with redirect dynamic pages based on ID and other parameters.

my .htaccess file looks like that right now:

RewriteCond %{REQUEST_URI}  ^/billboard_lokalizacja\.php$
RewriteCond %{QUERY_STRING} ^site=lokalizacje&id=([0-9]*)$
RewriteRule ^(.*)$ tablice_reklamowe/billboard_id/ [R=302,L]

when I enter url:

my-server/billboard_lokalizacja.php?site=lokalizacje&id=13

it redirects me to:

my-server/tablice_reklamowe/billboard_id/?site=lokalizacje&id=13

but i wanna to redirect from this urls:

my-server/billboard_lokalizacja.php?site=lokalizacje&id={NUMBER}
my-server/billboard_lokalizacja.php?site=lokalizacje&id={NUMBER}&variable=value
my-server/billboard_lokalizacja.php?site=lokalizacje&id={NUMBER}&variable=value&variable2=value2

to this one:

my-server/tablice_reklamowe/billboard_id/{NUMBER}

pls. Give me some advice, its hard to understand for me right now, but I need to run new page as soon as it is possible.

i thought i could made some redirect method in my controller and use rules like this:

RewriteCond %{REQUEST_URI}  ^/billboard_lokalizacja\.php$ [NC]
RewriteCond %{QUERY_STRING} ^site=lokalizacje&id [NC]
RewriteRule ^(.*)$ tablice_reklamowe/redirect/ [R=302,L]

but my Tablice_Reklamowe_Controller / redirect($string) method wont get access to $string.

$string is empty, current_url() returns only http://my-server/tablice_reklamowe/redirect.

How to solve my problem?

1 Answer 1

0

So, I know you're looking for a .htaccess solution, but I just did this in a very simple, SEO friendly way (and I don't want to mess with the voodoo of the .htaccess file):

<?php

class Old_controller extends MY_Controller
{
    function __construct() {
        parent::__construct();
        $this->load->helper('url');
        redirect(str_replace('old_controller', 'new_controller', "http://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"), 'location', 301);
        exit();
    }
}

Source: StackOverflow Question + Answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.