Redirect wrongly indexed Google pages to proper pages within my routes

82 views Asked by At

Google started indexing my site early, so some of the routes they have go to a nonexistant page, which throws a missing controller error.

Is there a way within my routes to explicitly redirect anything after a specific parameter to 301 redirect to the proper url?

Something like

<?
if ($this->params['wrongCategory']) {
$this->redirect('/properCategory');
}
?>

But ideally within my routes?

Router::connect('/wrongCategory/*', /*do a 301 redirect here */);
1

There are 1 answers

2
Paulo Rodrigues On BEST ANSWER

I believe it will be more efficient to make this permanent redirect through the file .htaccess in your root directory, something like this:

RewriteRule ^wrongCategory/(.*)$ /properCategory/$1 [R=301,L]