htaccess / routing CI2 + EasyPHP |
[eluser]Unknown[/eluser]
Hi All I have a problem with htaccess / routing and it's doing my head in now. I've been programming in PHP for 10+ years, CI for 2+ years, have used htaccess for many years for URL rewriting etc. I am reprogramming an old PHP website into CI. Most of it is working fine. I'm running EasyPHP on my laptop. Many CI websites work fine on this. One controller needs to use the old query strings - this is the shopping cart. The new controller receives the GET variables just fine. However, rewriting the old URLs to the new controller isn't working. The basic controller code is: Quote:class Mycart extends CI_Controller { The new URL to access this on my local dev server is: http://127.0.0.1/dev/mycart/?alpha=123&beta=234 That all works fine The old URLs on the old website used a cart URL like this: http://127.0.0.1/dev/cart/index.php?alpha=123&beta=234 In theory, it should be a simple to replace 'cart/index.php' with 'mycart/' in htaccess, but it just won't work This is part of my htaccess: Quote:<IfModule mod_rewrite.c> Please focus only on that one line. I have tried every combination of values left and right that I can think of, with and without leading slashes, absolute URLs etc - for example: RewriteRule ^cart/index\.php$ mycart [L] RewriteRule ^/cart/index\.php$ /mycart [L] RewriteRule ^dev/cart/index\.php$ dev/mycart [L] RewriteRule ^/dev/cart/index\.php$ /dev/mycart [L] RewriteRule ^/dev/cart/index\.php$ mycart [L] RewriteRule ^/dev/cart/index\.php$ /mycart [L] RewriteRule ^/dev/cart/index\.php$ dev/mycart [L] RewriteRule ^/dev/cart/index\.php$ /dev/mycart [L] RewriteRule ^/dev/cart/index\.php$ http://127.0.0.1/dev/mycart [L] (I've tried dozens and dozens of variations like these) I've also used (.*) and $1 in the correct places - no effect I've tried using RewriteCond %{REQUEST_URI} ^cart [NC] and variations of the RewriteCond - none of it works My apache (EasyPHP) log files report: /dev/cart/index.php?alpha=123&beta=234 HTTP/1.1 404 They are always the same (old) URL as typed into the browser Interestingly the following line 'works' and redirects to google: RewriteRule ^cart/index\.php$ http://google.com [L] However, the following line doesn't work at all: RewriteRule ^cart/index\.php$ http://127.0.0.1/dev/mycart [L] Any thoughts? I'm also using APP/core/MY_Router.php which has the following: function _set_request ($seg = array()) { // The str_replace() below goes through all our segments // and replaces the hyphens with underscores making it // possible to use hyphens in controllers, folder names and // function names parent::_set_request(str_replace('-', '_', $seg)); } This works fine too
[eluser]jonez[/eluser]
You should do rewrites in the router, this may be helpful: http://ellislab.com/codeigniter/user-gui...uting.html If you're trying to pass parameters to index() methods you'll need to use remap. Code: public function __construct( ) { |
Welcome Guest, Not a member yet? Register Sign In |