Welcome Guest, Not a member yet? Register   Sign In
Problem with Routes
#11

[eluser]Pascal Kriete[/eluser]
Even with :num, it's still a regular expression, so you need a capture group.

:num is internally replaced with \d+
:any is internally replaced with .+

Code:
$route['article/(:num)'] = "article/index/$1";

Your htaccess file would look like this:
Code:
RewriteEngine on

#Old urls first
RewriteRule ^/article\.php?aid=([0-9]+)$ /article/index/$1 [R=301,L]
# any other old urls here using the same schema

# Now the index.php
RewriteCond $1 !^(index\.php|public|user_guide|robots\.txt)
RewriteRule ^(.*)$ /domino/index.php?/$1 [L]
#12

[eluser]dootzky[/eluser]
@neen

nope. I know about case-sensitive PHP variables, but I still get nothing when routing with your code. Sad

@inparo

I've tried your .htaccess approach, but it's still not working. I'm realy confused, not sure what I'm doing wrong... :\

this is working:
/domino/article/84
/domino/article/index/84

and that's all good and normal, it works life before, as expected.

but this is stil not working:
/domino/article.php?aid=84

I don't even get redirected to "article" controller in CI, I just get "404 Page not found". :| why is that? Am I doing something wrong here? Sad

Are you sure that this will catch the 'old non-existing link':
Code:
#Old urls first
RewriteRule ^/article\.php?aid=([0-9]+)$ /article/index/$1 [R=301,L]

Please help me out just a little bit further, give me a doc-link to read if you don't have a solution, but I'm not sure why this is not working. And yes, mod_rewrite is working on my local (and production server) normally, I'm using it for some time now.

Any other .htaccess ideas? :|

Thanks again for help, to both of you.
#13

[eluser]dootzky[/eluser]
@inparo

I've just spent some time playing and blindly experimenting with the .htaccess line you've given me, and this is interesting, look what I've did:

Code:
RewriteEngine on

#Old urls first
RewriteRule article\.php /domino/article/index/$1 [R=301,L]
# any other old urls here using the same schema

# Now the index.php
RewriteCond $1 !^(index\.php|public|user_guide|robots\.txt)
RewriteRule ^(.*)$ /domino/index.php?/$1 [L]

look how I've edited your "article.php" RewriteRule, and this is what I get now, when I try to type in the URL:

Code:
# THIS IS THE OLD LINK, which acctually doesn't exists anywhere anymore...
http://localhost/domino/article.php?aid=84

I get redirected to:

Code:
http://localhost/domino/article/index/?aid=84

so this is great! Smile if this could work - that would solve my problem, right?
the only "problem" now, is that I still get NULL $article_ID passed to my index function. this is example code:

Code:
function index($id_article)
{
     var_dump($id_article);
}

and I get just "NULL".
that sucks. Tongue
if I could get anything -> at least the whole "?aid=84" part, I could easily cut out the needed article ID, but I'm inches away from getting that old $_GET value in CI...

any ideas now? Smile
#14

[eluser]Pascal Kriete[/eluser]
It's a regular expression, so to get the id, you need to capture that part. This should give you the whole query string:
Code:
RewriteRule article\.php[?](.+) /domino/article/index/$1 [R=301,L]
#15

[eluser]dootzky[/eluser]
hi again guys :wow:

ok, I've got it working.
it's not nice, it's not pretty - but it DOES WORK! Smile

first - your last idea with .htaccess didn't help, I was still getting "404 error" for "old link" (/domino/article.php?aid=84)

and then I did this, this is my working solution:

.htaccess file
Code:
RewriteEngine on

#Old urls first
RewriteRule article\.php /domino/article/index/ [R=301,L]

# Now the index.php
RewriteCond $1 !^(index\.php|public|user_guide|robots\.txt)
RewriteRule ^(.*)$ /domino/index.php?/$1 [L]

my routes.php setting:
Code:
...
$route['article/(\d+)'] = "article/index/$1";
...

and finally, my article.php controller:
Code:
...
...

function index($id_article)
{
    // if we don't get $id_article the normal way, try to hack the redirected URL, and get the ID..
    // if even that fails -> show_404();
    if (!$id_article) {
        $url = explode('/', $_SERVER['REQUEST_URI']);
        $fake_id = substr($url[4], 5, strlen($url[4]) - 5);
        
        if (is_numeric($fake_id)) $id_article= $fake_id;
        else show_404();
    }

    // do what you need to do here with your article..
}

...
...

so, for the normal page access, everything works. examples:
/domino/article/index/84 -> works
/domino/article/84 -> works
/domino/article/edit/84 -> works

and for the old "article.php" page attempt, this is what I get redirected to:
/domino/article.php?aid=84 => /domino/article/index/?aid=84

so - even if this is not "cool" solution, I somehow get to the "article" controller, and then I butcher the URL, and somehow I get the wanted ID. it will work for any ID length (84, 555, 1205, 44055 ..)

I really hope this will help someone else to get around the problems I've run to.
And of course, if someone here knows how do to this better - please do tell, I'll correct this solution then. Smile

And once again - I would like to say THANK YOU to both guys who've helped me out here, couldn't have done it without their help.

Cheers!
dootzky




Theme © iAndrew 2016 - Forum software by © MyBB