mod_rewrite and CodeIgniter question |
[eluser]ChrisF79[/eluser]
I'm new to CodeIgniter and I'm about to redesign a real estate site. Right now a URL is something like http://www.mydomain.com/Naples-Real-Estate/20384729/ where the 20384729 is the MLS Number for the database. I use explode to get that value with plain PHP. With CodeIgniter, would I still be able to use mod_rewrite to have that access a property.php sort of page? Thank you
[eluser]WanWizard[/eluser]
With CI you need mod_rewrite to get rid of the index.php in the URL. In general you don't need it to rewrite URL's. Assuming your property.php is (going to be) a controller, you can use a route to convert http://www.mydomain.com/Naples-Real-Estate/20384729/ to http://www.mydomain.com/property/index/N.../20384729/. You can then define your index method as Code: function index($name='', $MLS='') If you're not interested in the name, you can also use routes to remove that from the URI passed to the controller.
[eluser]ChrisF79[/eluser]
But then does the user see that long URL or the original one I posted?
[eluser]WanWizard[/eluser]
Routing is something that happens internally, the URI the user typed in doesn't change.
[eluser]ChrisF79[/eluser]
What would the route look like on something like that?
[eluser]WanWizard[/eluser]
Something like Code: // route all combinations of alphanumeric/numeric: You can even use a regex to match the weirdest combination of characters in the URI. Read up on URI Routing in the user guide.
[eluser]ChrisF79[/eluser]
That's super helpful. Thanks so much for all the replies. I'm headed off to try now. Thanks again!
[eluser]ChrisF79[/eluser]
[quote author="WanWizard" date="1284335754"]Something like Code: // route all combinations of alphanumeric/numeric: I tried adding your suggestion to my routes.php file. I have the url helper autoloaded in the autoload file. However, when I then try to visit http://localhost:8888/ci/Naples-Real-Estate/20292846/ I'm getting a not found error. It says: The requested URL /ci/Naples-Real-Estate/20292846/ was not found on this server.
[eluser]danmontgomery[/eluser]
Do you have mod_rewrite enabled and an .htaccess to remove index.php from your URL? Does http://localhost:8888/ci/index.php/Naple.../20292846/ work?
[eluser]ChrisF79[/eluser]
[quote author="noctrum" date="1284425526"]Do you have mod_rewrite enabled and an .htaccess to remove index.php from your URL? Does http://localhost:8888/ci/index.php/Naple.../20292846/ work?[/quote] So close! If I have in my routes.php file, $route['Naples-Real-Estate/(:num)'] = "property/naples/$1"; I get a CodeIgniter 404. If I take out the /naples/$1 part, I get a blank page. The weird thing is, my view just says in HTML "Your view has been loaded." I'm not even seeing that text. I did the mod_rewrite to remove the index.php so I think its loading the view but I have no way of knowing. |
Welcome Guest, Not a member yet? Register Sign In |