skip to Main Content

My website currently online is completely static and all the URLs have a trailing slash at the end : https://www.website.com/blog/article-1/

I’m working on my new website which is using Prestashop. On Prestashop, URLs don’t have a trailing slash : https://www.website.com/blog/article-1

Problem: I have an excellent SEO on my current website and I need to keep the actual URLs (with trailing slash) available. For user experience, I’d like URLs to work with or without trailing slash.

How can I redirect my new URLs to the same URL + trailing slash? If possible, I’d like to rewrite URLs so that users always see the URL with a trailing slash.

Example :

https://www.website.com/blog/article-1/ is redirected to https://www.website.com/blog/article-1 and the URL visible in the address bar is https://www.website.com/blog/article-1/.

2

Answers


  1. Well, ask “How can I redirect my new URLs to the same URL + trailing slash”…

    The answer obviously is: by implementing exactly that rule. There are thousands of examples for this alone here on SO. None of those helped? Why not?

    Anyway, here is another one:

    RewriteEngine on
    RewriteRule ^/blog/([^/]+)$ /blog/$1/ [R=301]
    RewriteRule ^/blog/([^/]+)/$ /blog/$1 [END] 
    

    You need to take care to send out references with leading slashes with this setup. Since otherwise your site will be dead slow, since the clients will have to request every single page twice due to the redirection then required for every single page…

    It is a good idea to start out with a 302 temporary redirection and only change that to a 301 permanent redirection later, once you are certain everything is correctly set up. That prevents caching issues while trying things out…

    In case you receive an internal server error (http status 500) using the rule above then chances are that you operate a very old version of the apache http server. You will see a definite hint to an unsupported [END] flag in your http servers error log file in that case. You can either try to upgrade or use the older [L] flag, it probably will work the same in this situation, though that depends a bit on your setup.

    This rule will work likewise in the http servers host configuration or inside a dynamic configuration file (“.htaccess” file). Obviously the rewriting module needs to be loaded inside the http server and enabled in the http host. In case you use a dynamic configuration file you need to take care that it’s interpretation is enabled at all in the host configuration and that it is located in the host’s DOCUMENT_ROOT folder.

    And a general remark: you should always prefer to place such rules in the http servers host configuration instead of using dynamic configuration files (“.htaccess”). Those dynamic configuration files add complexity, are often a cause of unexpected behavior, hard to debug and they really slow down the http server. They are only provided as a last option for situations where you do not have access to the real http servers host configuration (read: really cheap service providers) or for applications insisting on writing their own rules (which is an obvious security nightmare).

    Login or Signup to reply.
  2. If you mean default prestashop links like products, categories etc. you can just change their way to be built. Prestsahop allows us to achieve this within admin-panel Configure->Shop Parameters->Traffic & SEO->SEO and URL's>Schema of URLs (for PS 1.7).
    And there change an URL in interest, for example, Route to category
    from {id}-{rewrite} to {id}-{rewrite}/. And you won’t need to redirect anything.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search