Jump to content

Correct way to perform a 301 redirect in Prestashop


chrisdac

Recommended Posts

Hi,

 

I'm having no luck getting any redirects to work in a new Prestashop 1.5.4 site that has just gone live. I have tried many different permutations, but none of them work. I have tried placing them outside of Prestashop's ~~start~~ and ~~end~~ points in .htaccess, and out of desperation have also tried placing them inside it, even though we are not supposed to! Nothing is working.

 

I have tried this:

 

 

Also this:

 

RewriteCond %{HTTP_HOST} ^example.com$

RewriteRule ^old_folder/old_file.html$ http://example.com/n...r/new_file.html [R=301,L]

 

And someone even suggested this, even though I had not encountered the syntax before:

 

Redirectmatch 301 http://OLD_URL http://NEW_URL

 

None of them work - I am always directed to Prestashop's "Page not available - We're sorry, but the Web address you entered is no longer available" page (which I'm assuming is its default 404 page).

 

So how can we accomplish a standard 301 redirect in Prestashop?

 

Thanks

Edited by chrisdac (see edit history)
Link to comment
Share on other sites

UPDATE:

 

We have made some progress but there is still some strange behaviour:

 

1) Adding RewriteRule ^OLD_URL$ NEW_URL [R=301,L] immediately after the "RewriteEngine on" statement (i.e. inside the code that Prestashop rewrites ) get us half way there - the redirect occurs, but then Prestashop always appends ?controller=404 to the end of the new URL. No idea why it is doing this.

 

2) Adding the above code after the closing ~~end~~ code in .htaccess (i.e. where Prestashop tells us we are supposed to put the code...) results in no redirect taking place whatsoever, so here the code is just getting ignored.

 

Any help much appreciated... this is basic stuff for any site and we urgently need a fix, but I have no idea why Prestashop is getting in the way of a simple redirect.

 

Thanks

Link to comment
Share on other sites

Final update:

 

After hours of tearing my hair out (and discovering a huge number of people online who are having similar difficulties) I gave up and implemented a rather hacky system inside index.php which works fine. The code I used was placed at the top of index.php, before any other code is run, and is along these lines:

 

if (strpos($_SERVER['REQUEST_URI'], OLD_URL_GOES_HERE) !== false) {

header("HTTP/1.1 301 Moved Permanently");

header("Location: OLD_URL_GOES_HERE");

exit();

}

 

To be honest, it's very disappointing that not only is the broken .htaccess behaviour not acknowledged anywhere in the Prestashop documentation, but there is no guidance anywhere on how to accomplish what is a very routine task that has such a large effect on SEO - and therefore sales. When code that works in all other web applications doesn't work in Prestashop, we should at least be told why and given an alternative. Instead I've had to resort to hacking code that will make the site more difficult to update.

Edited by chrisdac (see edit history)
  • Like 3
Link to comment
Share on other sites

  • 2 weeks later...
  • 2 months later...

I have to agree with Chris. It sucks to get involved and reliant on a service so good as PrestaShop, and to fund this by buying modules and such, to have simple procedures you would never expect to be an issue become one. In turn effecting business and our jobs.

Link to comment
Share on other sites

  • 1 month later...
  • 2 months later...

You guys are discussing .htaccess directives which are part of Apache and not Prestashop. Anything that happens in an .htaccess file occurs before Prestashop has been loaded in any way. Here are some tips with working with htaccess:

 

 

If you're using CGI or FastCGI you will have different behavior. In particular if you are getting a blank page response or a lower-level Apache error you might be encountering CGI permission or path issues.

 

Test your redirects in the terminal with wget otherwise you're getting heavily cached results in most browsers and especially Chrome. Even with other caching disabled you may still be getting the HTTP headers cache. This is compounded with ineffective cache-clearing tools () You are better off not testing redirects in the browser until they work in the terminal

 

Understand that Apache can be configured in many different ways and what you see working for someone may not work for you because of this. For example, your directory structure combined with MultiViews may be propagating to a different .htaccess file.

Also if you're not mindful of Query String Append (QSA) and telling the rewrite engine (mod_rewrite) to stop rewriting (with the [L] flag) it may be just skipping your rule and doing a different rule.

RewriteRule ^allThingsGood index.php [L] # Match and finish with index.php no more rewriting

Also test to make sure your host has mod_rewrite by removing the <if> checks in the .htaccess. If mod_rewrite is not installed/enabled it will 503 ISE, as any invalid .htaccess file will cause a HTTP 503.

Link to comment
Share on other sites

The forum ate my last comment! It was supposed to mention that if you are using Chrome use the NET-INTERNALS page to clear the HTTP header cache which is different from the normal cache.

 

about : / / net-internals

 

Takes you to the special page in Chrome that does this.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...