开发者

Cakephp, Route old google search results to new home page

I have created a new website for a company and I would like all the previous search engine results to be redirected. Since there were quite a few pages and most of them where using an id I would like to use something generic instead of re-routing all the old pages.

My first thought was to do that:

Router::connect('/*', array('controller' => 'pages', 'action' => 'display', 'home'));

And put that at the very end of the routes.php file [since it is prioritized] so that all requests not validating with previous route actions would return true with this one and redirect to homepage.

However this does not work.

When I use a different path on the Router it redirects successfully. For example if I give it:

Router::connect('/*', array('controller' => 'projects', 'action' => 'browser'));
开发者_Go百科

it works fine. The problem arises when the controller used is pages, action display etc.

I'm pasting my routes.php file [since it is small] hoping that someone could give me a hint:

    Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));

    Router::connect('/company/*', array('controller' => 'articles', 'action' => 'view'));

    Router::connect('/contact/*', array('controller' => 'contacts', 'action' => 'view'));

    Router::connect('/lang/*', array('controller' => 'p28n', 'action' => 'change'));

    Router::connect('/eng/*', array('controller' => 'p28n', 'action' => 'shuntRequest', 'lang' => 'eng'));

    Router::connect('/gre/*', array('controller' => 'p28n', 'action' => 'shuntRequest', 'lang' => 'gre'));


    Router::parseExtensions('xml');


Instead of trying to handle everything within the cakePHP route file, I would recommend that you use the .htaccess file to 301 redirect pages as necessary.

What you have above will not transfer the rankings over because as far as i can see there is no 301 redirect being outputted in any of the routes.php based solutions you proposed.


The bigger problem is that a Route doesn't redirect, it connects URLs with responses. In other words, it makes sure that your now invalid URLs still yield a valid page. Which is exactly the opposite of what you want to achieve.

You want to tell visitors that a URL that used to be valid isn't anymore. You do this by issuing appropriate HTTP response codes, 301 Moved Permanently in this case. Without doing this the URLs will still appear valid to search engines and they won't update their index.

You'd either have to connect all the invalid URLs via Routes to some controller action that'll issue a $this->redirect('...', 301) or you could use some .htaccess rules to redirect. Which one to use depends on the complexity of the redirect, but you'll probably be able to use simple .htaccess mod_rewrite rules.

There are enough examples on SO: https://stackoverflow.com/search?q=htaccess+301+redirect

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜