cakephp - URL rewriting in Cake -


i need rewrite url in cake application in such way slug (e.g. title) shown in url. example, if have cake url www.site.com/users/view/1 (controller/action/id), need show /vikram.sinha if user's nick vikram.sinha (no id, no action, no controller or else in url).

i making sure title (slug) unique before storing , best following.

www.site.com/profile/vikram.sinha adding route below.

router::connect('/profile/:slug', array('controller' => 'users', 'action' => 'view'),         array(             'pass' => array('slug'),         )); 

the problem facing need remove profile url. couldn't find way rewrite url in cake without adding before slug.

or may url can rewritten using htaccess directly not either. if suggesting using htaccess please assume url need changed www.site.com/users/view/vikram.sinha

thanks!

your best bet imo reddit each slug prefixed /r/.

example:

mysite.com/u/johnsmith 

then, in routes, can this:

router::connect('/u/:slug/*', array('controller'=>'users', 'action'=>'view'),      array('pass'=>array('slug'))); 

if don't want that, can use like:

router::connect('/:slug/*', array('controller'=>'users', 'action'=>'view'),      array('pass'=>array('slug'))); 

but keep in mind, other controllers, plugins...etc etc etc need own routes, since think passed after mysite.com/ uname. not best idea imo.


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -