Welcome Guest, Not a member yet? Register   Sign In
.htaccess, rewrite URI to function, pass URI to codeigniter
#1

[eluser]x_dde_x[/eluser]
Hey there,

I'm in the process of making the switch to CodeIgniter. I usually write my own custom MVC system for each site that I create, but I'm starting to come around to the idea that CodeIgniter won't unduly decrement my site's performance. Maybe I'm a bit of a troglodyte in this regard.

Anyway, I'm converting an existing site of mine to CodeIgniter as an experiment, and am having difficulty with the mod_rewrite aspect. Maybe this isn't something that CodeIgniter can do, or possibly I'm going about it the wrong way. Here's the conundrum (for a custom guitar builder's site).

I want the URL to read:
Code:
http://URL.com/custom_guitars/NAME_OF_GUITAR

Where NAME_OF_GUITAR is a variable that I pass to a codeigniter function called guitar_name. I've already found that codeigniter doesn't like guitar_name=$1.

The .htaccess is setup as so:
Code:
RewriteRule ^custom_guitars/([A-Za-z_]+)$ index.php?cusom_guitars/guitar_name/$1 [L]

Any ideas?
#2

[eluser]x_dde_x[/eluser]
Oh, found it.... Routes...

Smile
#3

[eluser]got 2 doodle[/eluser]
Hey there back. I know there is plenty of tweaking available in the routing capabilities of CI.

For an example of what I did on a site that had numerous educational programs this is what the url looks like

Quote:http://www.tatacentre.ca/index.php/programs/details/61

So index.php I can remove with .htaccess but it is left in place because I am having a problem with SSL and .htaccess - I discuss it here (maybe you can help!!)

Anyway, assuming you are quite new to codeignitor the url works like this

the controller is called programs.php.
details is a function within that program.
61 is the id of the database entry that has all the juicy details, but it could just as easily be the name of the guitar.

Embrace the MVC architecture

Read the manual here and here

I think you will find that what you want to accomplish is very do-able.

Also don't even touch .htaccess (don't use it) until you have the application working the way you want it to, it can lead to errors and confusiion.

doodle




Theme © iAndrew 2016 - Forum software by © MyBB