Cakephp change url to new url

I have CakePHP (version 2.1.3) that is already running (on Centos 6.x and Apache).

Now I want to change the url: http://domain.com/frontend/login

to the new URL, for example: http://domain.com/user-login.html

I changed route.php as shown below:

Router::connect(
    '/:slug.html', 
    array('controller' => 'frontend', 'action' => 'login'),
    array(
        'pass' => array('slug')
    )
); 

and added my login.ctp code:

<?php 
 echo $html->link('user login', 
        array(  
            'controller' => 'frontend',    
            'action' => 'login',    
            'slug' => Inflector::slug('user login'))); 
?>

This is a success, and now I can access with the new URL: http://domain.com/user-login.html

But I can also access with the old URL: http://domain.com/frontend/login

I only want to access the new URL and delete the old URL.

How can i do this? please tell me the details.

Thank.

+4
source share
2 answers

Ptica's answer is good, but if you want something that doesn't disable all of the default CakePHP routes, I would add redirection rules to the .htaccess file: -

Redirect 301 /frontend/login /user-login.html

.htaccess - , , . , ; - , !

, , : -

  • Cake Router/HtmlHelper ,
  • URL , URL

, /frontend/login.

+2

routes.php : /** * Load the CakePHP default routes. Remove this if you do not want to use * the built-in default routes. */ require CAKE . 'Config' . DS . 'routes.php';

just comment out the line requireand you should all be set

+1
source

Source: https://habr.com/ru/post/1589340/


All Articles