CodeIgniter Forums
.htaccess weirdness - 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 weirdness (/showthread.php?tid=33093)



.htaccess weirdness - El Forum - 08-15-2010

[eluser]SitesByJoe[/eluser]
Ok, this is a little offtopic from CI, but I need smart brains to help me figure this out!

I had a website running on procedural PHP from years ago I just updated to run on CI.


The old site had .htaccess rewrite rules redirecting things.

Now that the site is on CI the rewrites aren't working.

I need to change this url:
http://www.seaislerealty.com/2010-LERS04-0047

to this url:
http://www.seaislerealty.com/index.php/rentals/detail/0047/LERS04/2010/

and I've placed the following on my .htaccess file:
RewriteRule ([0-9]{4})-([0-9a-zA-Z]+)-([0-9a-zA-Z]+)$ /index.php/rentals/detail/
$3/$2/$1/ [L]

Before, the rewrite rule worked fine. Now I get a "no input file" error. Something's not right but the regex looks fine.

Any thoughts?

Thanks!


.htaccess weirdness - El Forum - 08-15-2010

[eluser]pickupman[/eluser]
You may also want to try and use routes. Leave .htaccess to the standard:
Code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

//application/config/routes.php
$route['([0-9]{4})-([0-9a-zA-Z]+)-([0-9a-zA-Z]+)'] = 'rentals/detail/$3/$2/$1';

Or try this
Code:
RewriteEngine On

RewriteRule ^([0-9]{4})-([0-9a-zA-Z]+)-([0-9a-zA-Z]+)$ index.php/rentals/detail/$3/$2/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]



.htaccess weirdness - El Forum - 08-15-2010

[eluser]SitesByJoe[/eluser]
Using routes was a good idea.

The trouble I'm having now is that rentals/detail/etc/etc/etc can't read data out of the uri segments. Try the link:

http://www.seaislerealty.com/2010-LERS04-0047

How do I get the data out of the re-written uri?


.htaccess weirdness - El Forum - 08-15-2010

[eluser]pickupman[/eluser]
Instead of $this->uri->segment(), use $this->uri->rsegment(). rsegment is for routed uris. In the user guide [url="http://ellislab.com/codeigniter/user-guide/libraries/uri.html"]uri class[/url] provides all the same methods except prepending r for routed uri's.


.htaccess weirdness - El Forum - 08-15-2010

[eluser]SitesByJoe[/eluser]
Nice one! I should have checked the user guide...