![]() |
HTACCESS - A Complex Problem - 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: HTACCESS - A Complex Problem (/showthread.php?tid=32364) |
HTACCESS - A Complex Problem - El Forum - 07-21-2010 [eluser]vanquish[/eluser] Hello all, I have been have some big struggles trying to exclude a particular URL from being rewritten by CodeIgniter. The Situation: I have almost all URL requests being routed through my "pages" controller, which looks up the URL segment in the database and returns a page if a match exists. The Exception: However, there are certain sections of the site that I do *not* want pushed through the pages router. For example, my authentication controllers have to be separate from the pages. Using the .htaccess file listed below, I cannot for the life of me figure out an exception for the auth controller. I want to rewrite: /auth -> index.php/auth/login (erroneously tries to reach index.php/pages/load_page/auth/login - causes 404!) /auth -> index.php/auth/register (erroneously tries to reach index.php/pages/load_page/auth/register - causes 404!) Code: <IfModule mod_rewrite.c> If anyone has any insights, it would be greatly appreciated ![]() HTACCESS - A Complex Problem - El Forum - 07-21-2010 [eluser]mddd[/eluser] Why are you doing this in .htaccess? Just change this: Code: RewriteRule ^(.*)$ index.php/pages/load_page/$1 [L] Code: RewriteRule ^(.*)$ index.php/$1 [L] and do the routing in your routes.php: Code: $route['auth/(:any)'] = 'auth/$1'; // this doesn't change a thing for any url starting with auth/ HTACCESS - A Complex Problem - El Forum - 07-21-2010 [eluser]Unknown[/eluser] I'm with mddd. Routing is definitely your friend for what you're trying to do. http://ellislab.com/codeigniter/user-guide/general/routing.html HTACCESS - A Complex Problem - El Forum - 07-22-2010 [eluser]vanquish[/eluser] [quote author="mddd" date="1279733402"]Why are you doing this in .htaccess? Just change this: Code: RewriteRule ^(.*)$ index.php/pages/load_page/$1 [L] Code: RewriteRule ^(.*)$ index.php/$1 [L] and do the routing in your routes.php: Code: $route['auth/(:any)'] = 'auth/$1'; // this doesn't change a thing for any url starting with auth/ Thanks for the replies guys! Great idea in concept, but it did not work in practice. I made the changes exactly, but now all pages are just going to "load_page" and no URL parameters are being passed through. I can click any page of the site, and it is just the same controller always being loaded. The auth controller is never touched. I tried changing the single quotes ' to double quotes " in the routing rule, and that did not work either. HTACCESS - A Complex Problem - El Forum - 07-23-2010 [eluser]mddd[/eluser] Did you put them in the right order? If you put the second route first, it will match EVERYTHING. So then you'll never get to the auth controller. Always put the most specific route first and the most generic route last. With the routes I described, anything starting with 'auth/' should be going to the auth controller. Looking at it again, I do see a mistake on my part: I wrote Code: $route['auth/(.*)'] Code: $route['auth(.*)'] = 'auth$1'; HTACCESS - A Complex Problem - El Forum - 07-23-2010 [eluser]vanquish[/eluser] The auth route actually worked - it was a caching issue in Google Chrome that wasn't showing the correct page. I figured out the problem with the rest of the pages too! My URL segment order had changed, and unfortunately there was no warning of this in the routes documentation. So I had to change $this->uri->segment(4) to $this->uri->segment(2), etc and all was good!! Thanks so much guys! People on this forum are brilliant. |