gargi gargi - 7 months ago 15
PHP Question

301 Redirect from old URL not working (prestashop)

I have a new site for an existing domain.

I want to redirect the old URLs to the new site, but the simple way of:
Redirect 301 oldURL newURL
isn't working.

I was told that there's a problem with the fact that the old URL contains index.php in it,
and that I need a rewrite rule for it...

example for new/old URLs:

old: http://www.example.com/index.php?type=store&category=11&subcategory=15&item=67

new: http://www.example.com/64-white-

would appreciate help with the rule I need to insert to the HTACCESS

tnx ahead

Guy

Answer

There are several ways to create a permanent redirect in .htaccess:

RedirectPermanent /index.php?type=store&category=11&subcategory=15&item=67 http://www.example.com/64-white-
Redirect 301 /index.php?type=store&category=11&subcategory=15&item=67 http://www.example.com/64-white-
RedirectRule /index.php?type=store&category=11&subcategory=15&item=67 http://www.example.com/64-white- [L,R=301]

Although, since you are talking about redirecting from index.php I would advise you to consider doing the redirect in code.

for examlple, you can create an oldsite_redirects.php file like this:

<?php
$redir_maps = array(
'/index.php?type=store&category=11&subcategory=15&item=67' => '/64-white-'
);

if(in_array(@$_SERVER['REQUEST_URI'], array_keys($redir_maps))){
header("HTTP/1.1 301 Moved Permanently"); 
header("Location: ".$redir_maps[@$_SERVER['REQUEST_URI']]);
exit;
}
?>

And in the index.php file add the following line ABOVE all code and comments:

require_once('oldsite_redirects.php');

hope this helps.

Comments