How to create a 301 or 302 redirect in PrestaShop 1.7?

by jose_gulgowski , in category: SEO , a year ago

How to create a 301 or 302 redirect in PrestaShop 1.7?

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

3 answers

Member

by mabelle , a year ago

@jose_gulgowski 

In PrestaShop 1.7, you can create a 301 or 302 redirect using the built-in URL redirection feature. Here are the steps to follow:

  1. Log in to your PrestaShop 1.7 admin panel.
  2. Go to the "Traffic & SEO" section in the left-hand menu and select "URL Redirects."
  3. Click on the "Add new" button.
  4. In the "From" field, enter the URL of the page that you want to redirect.
  5. In the "To" field, enter the URL of the page where you want to redirect the traffic.
  6. Choose the redirection type (301 or 302) from the drop-down menu.
  7. Click on the "Save" button to create the redirect.


That's it! Your new redirect is now created and will direct traffic to the designated URL based on the redirection type you chose.

Member

by maci , 4 months ago

@jose_gulgowski 

Please note that in PrestaShop 1.7, the URL redirection feature is limited to redirecting specific URLs to other URLs within your shop. If you need more advanced redirection options or want to redirect an entire category or product to a different URL, you may need to use a module or modify the code directly.

Member

by mabelle , 3 months ago

@jose_gulgowski 

To create more advanced redirects or redirect entire categories or products in PrestaShop 1.7, you can use a module or modify the code directly. Here are the steps to accomplish this:

  1. Using a Module:
  • Search for a URL redirection module in the PrestaShop marketplace or from third-party providers.
  • Choose a module that supports advanced redirection options and compatibility with PrestaShop 1.7.
  • Install the module on your PrestaShop website following the instructions provided by the module developer.
  • Configure the module settings according to your requirements, specifying the source URL(s) and the target URL(s) for your redirect.
  1. Modifying the Code:
  • Access your PrestaShop files using an FTP client or File Manager provided by your hosting provider.
  • Locate the file "classes/Dispatcher.php" in your PrestaShop root directory and open it in a text editor.
  • Search for the function "dispatch()" within the file.
  • To redirect an entire category or product, you can modify the code within the "dispatch()" function using a logic to check for the specific category or product ID and redirect it to the desired URL. For example, you can add the following code before the return statement:
1
2
3
4
5
6
if (your_category_id_here) {
    $url = 'your_desired_url_here';
    header("HTTP/1.1 301 Moved Permanently");
    header("Location: $url");
    exit();
}


  • Save the changes to the file and upload it back to your server, replacing the old file.
  • Clear your PrestaShop cache to ensure the changes take effect.


Please note that modifying the code directly requires technical knowledge and it's recommended to make a backup of your website before proceeding. It's also important to be cautious to avoid any errors that may result in the malfunctioning of your PrestaShop.