cakephp Fix Url redirection

2019-09-08 08:57发布

问题:

OLD ---> NEW

http://abc.com/cities/view/1 -->http://abc.com/melbourne-day-tours/

http://abc.com/categories/view/3 -->http://abc.com/melbourne-day-tours/great-ocean-road-tours

http://abc.com/tours/view/1 -->http://abc.com/melbourne-day-tours/great-ocean-road-tours/great-ocean-road-adventure-tour

i do have an old project , now i have to do following redirection , what should i do ? using htaccess ? or any other ways ?

when i put http://abc.com/melbourne-day-tours/ in my bro, the url in the address bar shd be stay same, and it be call controller and the action for http://abc.com/cities/view/1 thanks

回答1:

The best way of of doing this is using the CakePHP Router. You can set routes in app/Config/routes.php, for example:

Router::connect(
    '/melbourne-day-tours',
    array('controller' => 'cities', 'action' => 'view', 1)
);

If you are planning having many routes you might be better of using slugs which are stored in your database. There is some information about that in the link above.



回答2:

What i just done is :

i just done is just putted lines in app/webroot/.htaccess

RewriteRule ^melbourne-day-tours/?$ /cities/view/1 [L]

it worked ! thanks !