Forum Moderators: phranque

Message Too Old, No Replies

Removing dir from friendly url with rewrite

         

xKillswitchx

7:06 am on Jan 26, 2010 (gmt 0)

10+ Year Member



I am having a really hard time trying to grasp this. I have a friendly url rewrite already setup to get friendly urls with my MVC app...

RewriteRule ^(.*)$ index.php/$1 [PT,L]

This is decent so far, but I want to remove a piece of a url in my content controller, so things go from...to...

site.com/content/index/chevrolette/corvette

site.com/content/chevrolette/corvette

Essentially, only in content/ do I want the index/ removed from the URL. Can anyone help me with this if its possible?

jdMorgan

4:03 pm on Jan 26, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This change has to be done within the code that generates links on your pages.

Realize that the code you posted does not change the URLs. All it does is take an incoming client request for the "friendly" URLs --and actually, for *all* URLs-- and internally rewrite that to your index.php script. The URL itself is set/defined by the link that appears on your pages, and cannot be changed by any server-side code.

So you need to modify your "controller."

Also, be aware that having done so, your controller will also need to be modified to re-inject "/index" into the 'path' wherever and whenever it is required. You'll either need to re-inject it in *all* cases, or you'll need to go check the database twice -- once with "/index" in the path, and once without. If the database returns a valid entry in both cases, then you have an irresolvable naming conflict, and will have to just 'pick one'.

Jim