![]() |
Rewrite URL's - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Rewrite URL's (/showthread.php?tid=24226) |
Rewrite URL's - El Forum - 11-03-2009 [eluser]Guido Mallee[/eluser] Hi, Im building a webshop on CI and I'm implementing a paymenth method called iDEAL, which is a Dutch payment method. During the checkout proces, the visitor leaves the website to do the iDEAL transaction, then iDEAL sends the visitor back to the webshop like this: http://www.mywebshop.nl/checkoutcomplete/?trxid=0000000000008246&ec=d610dea309bc73c4a66867bf7e92dfc7b72e610d Since I'm using seo friendly url's, CI doesnt allow this url. I would like to rewrite the url to the following: http://www.mywebshop.nl/checkoutcomplete/0000000000008246/d610dea309bc73c4a66867bf7e92dfc7b72e610d I've tried to edit my .htaccess but I didn't even manage to make a simple rewrite from for example product.php?id=12 to product/12 This is my .htaccess file: Code: ErrorDocument 404 /index.php Thanks in advance! Rewrite URL's - El Forum - 11-03-2009 [eluser]BrianDHall[/eluser] Just as an alternative, you could enable query strings, probably need to set uri_protocol to PATH, and just use regular rewrites inside CI to handle this in the routes.php file. Rewrite URL's - El Forum - 11-03-2009 [eluser]Guido Mallee[/eluser] Thanks for your tip. Seems like a perfect alternative. But how do i do the regular rewrite part? When i use a '?' in my route index, CI says no... Rewrite URL's - El Forum - 11-03-2009 [eluser]JoostV[/eluser] Hi Guido, you can easily tackle this in two ways: 1. Ugly hack, but works fine - in the top of your index.php, store the GET vars in global constants: Code: define('C_TRIXID', (int) $_GET['trxid']); 2. Do not define these globals by hacking your index.php, but define them in a pre_system hook instead. Add to config/hooks.php: Code: $hook['pre_system'] = array( Code: /** So, no need for .htaccess modifications or enabling GET. Rewrite URL's - El Forum - 11-03-2009 [eluser]Guido Mallee[/eluser] Thanks! I'll try this the first thing tomorrow! But this way, the url itself doesn't change, does it? I could redirect then of course to a seo friendly url, but is there an other way to acomplish this? Rewrite URL's - El Forum - 11-03-2009 [eluser]BrianDHall[/eluser] [quote author="Guido Mallee" date="1257302662"]Thanks for your tip. Seems like a perfect alternative. But how do i do the regular rewrite part? When i use a '?' in my route index, CI says no...[/quote] Here you go: http://ellislab.com/forums/viewthread/133908/ Basically what I do is in my routes.php file I check $_GET - which still exists because I enable query strings. The nice thing is that you aren't forced to use GET - it just becomes an option you can freely intermix with CI-style url segments. If any of this doesn't make sense just let me know and I'll try to be a little more specific. The use of conditionally setting routes based upon GET usage allows you to accomplish things you otherwise have to do a lot of work to accomplish. As the hook method demonstrates there is more than one way to handle things, but I really like the flexibility of handling GET and POST - I really think it is how CI should be configured by default. Rewrite URL's - El Forum - 11-04-2009 [eluser]JoostV[/eluser] @guido: no, the url stays like http://www.mywebshop.nl/checkoutcomplete/?trxid=0000000000008246&ec=d610dea309bc73c4a66867bf7e92dfc7b72e610d But like Brian says, there are more than one way to tackle this. His way is probably more generic. Rewrite URL's - El Forum - 11-04-2009 [eluser]Guido Mallee[/eluser] Ok, no problem. For now I'll use this method then, so i can continue the project, but i still hope someone can tell me how I can change the url itself.. Rewrite URL's - El Forum - 11-04-2009 [eluser]JoostV[/eluser] You might find the answer here Rewrite URL's - El Forum - 11-05-2009 [eluser]Guido Mallee[/eluser] Thanks, I found the answer there indeed! For those who want to know how I resolved my problem, I adjusted my .htaccess file to this: Code: ErrorDocument 404 /index.php |