System for 301 Redirects on discontinued product pages

Has anyone done any work to use 301 redirects when a product is discontinued on the web site or when a static page is taken down? Here is a Use Case:

Product “A” has been for sale on the web site for a while. Google has indexed it and some bloggers and article writers have recommended it and included a link to the product on their web site. (Which Google has also indexed.)

But Product “B” has been introduced as a new and improved version of Product “A” which is now discontinued.

Visitors from Google or blog posts want to see Product “A” but will see a 404 page if there isn’t a 301 Redirect set up to take them to Product “B”. Google will also deprecate the site’s SEO value if they see a 404.

The solution is probably two-fold. One would be a 301 module that is just a table with a list of every “old” URL and the “new” URL that it should point to. The second part would be to bury the same functionality in an item page record so that when it is deactivated or out-of-stock it would have a URL to go to (even if it is just the home page).

Anybody got a solution/work around?

1 Like


Generally, 301 redirects are handled at a server level and seldom at an application level

Depending on what access you have to the server you have two options

  1. Use .htaccess to implement the 301 redirect
  2. As an example using PHP you create a php page with a filename that references your old product and insert the code below.
header("HTTP/1.1 301 Moved Permanently"); 

I am not certain that ERPNext is able to do 301 redirects

Hope this helps

Thanks @saidsl. I have used a 301 tool in Netsuite and I can see a need for it in our upcoming project. I appreciate the insights on .htaccess. That will help.

We had a case for our client where old urls needed to redirected to new products and even new pages when we moved them from drupal to frappe.

The simplest solution was to setup a redirect map for them on nginx config. We keep the map in a separate file so that if we need to regenerate the nginx config we don’t have to redo the map.

Something like:

redirect-map.conf ---------------------------

map $request_url $redirect_url {
  ~^/product/sku1 /product/sku2

Then at the top of your nginx config file or even the global nginx config file:

# setup map
include /path/to/your/map/file/redirect-map.conf

And finally to trigger the map inside your server virtual host configuration:

server {
  listen 443;

  ... stuff ...
  # put this before all other "location" keyword so we can redirect any url we want
  if ( $redirect_uri ) {
    return 301 $redirect_uri
  ... other stuff ...


I should point out that using maps are great for regex based redirects so that you can do interesting things with urls.

Here is a good tutorial on how this works:


@Felipe_Orellana That is a 10/10 answer. Thank you very much. We will put it to work.

1 Like