EllisLab text mark
Advanced Search
     
How to remove GET parameters to avoid a 404?
Posted: 06 September 2007 03:41 AM   [ Ignore ]
Joined: 2007-05-31
19 posts

Hi,

We’re migrating our old site to CodeIgniter and are using the Redirect directive in Apache to handle the redirects to our new pages. Our QA just discovered that the Redirect directive will add all the old links’ GET parameters to the new CI urls and cause the new CI links to die a nasty 404 death.

So, the question is: what’s the best way to chop the GET parameters before CI chokes? Should I use a hook? Are there any suggested or tested / proven solutions to this problem?

Any help is appreciated!

 
Posted: 06 September 2007 04:14 AM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Joined: 2007-05-31
19 posts

Ok, I think we have to handle this in the .htaccess file.

This is the key line:

RewriteRule ^(.*)$ index.php/$1 [L] 

If I change it to this, it simply doesn’t work and 404s before it even gets to CI.

RewriteRule ^(.*)\?(.*)$ index.php/$1 [L] 

Also doesn’t work:

RewriteRule ^(.*)(\?)(.*)$ index.php/$1 [L] 

I’m trying to find the question mark and GET parameters and just not pass them to CI. Any one with an effective rule in this case?

 
Posted: 06 September 2007 07:40 AM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Joined: 2007-05-31
19 posts

Many more attempts to do this through .htaccess have been futile, so I’m going to look into the hooks method. Does anyone know how to access the URL in the pre_system stage?

 
Posted: 06 September 2007 08:32 AM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2007-08-14
12 posts

Hey there, I did something similar not too long ago, where I was reformatting the URL (with GET query) into CI-friendly URLs. If you use a pre-system hook, you won’t have any CI stuff to work with, really. This comes before routing letalone extra libraries/helpers. So, I just used straight PHP to do it. Grab the $_GET variable and do what you want to it (in your case nothing) and then send a Header(“Location: [your-page]”).

However, I’m a noob so take this advice with a pinch of salt smile

As for accessing the URL with PHP -> parse_url() is probably what you’re after.

 Signature 

Nillian - Newbie CI coder

 
Posted: 06 September 2007 08:33 AM   [ Ignore ]   [ # 4 ]   [ Rating: 0 ]
Avatar
Joined: 2006-11-05
96 posts

Hi Mipa,

Try this simple trick: change this line in the config.php:
from

$config['uri_protocol']  'AUTO'

to

$config['uri_protocol']  'PATH_INFO'

This hint was from Joeles and helped me.

 Signature 

When a good coder dies, he degrades gracefully…

My Website |
Follow me on Twitter

 
Posted: 06 September 2007 10:11 AM   [ Ignore ]   [ # 5 ]   [ Rating: 0 ]
Joined: 2007-05-31
19 posts

Thanks, mate! That was a big part of us finding a solution. In the end, we changed to PATH_INFO and then we also used a “pre_system” hook to analyze the REQUEST_URI for GET parameters and take the appropriate action.

Cheers.