Redirects are always treated as a Poor SEO practice. By redirecting your website, you are making your precious customers wait for quite a long time to display them what they love to see. Redirections not only slowly renders your website but also directly irritates your valuable customers and force them to leave your website.
Redirections on landing pages add delays to the page load and while the redirections are occurring, nothing is shown to the client. In many cases, redirections can be eliminated without changing the function of a page.
How To Bypass Redirects:
The trick lies in the order of the rewrite rules. The rules will be read from top to bottom. Begin with the check for the trailing slash followed by www and finally https. This way, if the URL ‘violates’ any of the specifications, it will be redirected only once.
Therefore, the discussion should not be around when to use the trailing slash, but how to correctly implement its check order in the .htaccess file. This way, even if you use it on a file, there will only be one redirect. If you use it on a directory, then there will be no redirects.
Here is the correct code to add to your .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} /(.+)/$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ https://www.example.com/%1 [R=301,L]
RewriteCond %{REQUEST_URI} !(.+)/$
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+)$ https://www.example.com/$1/ [R=301,L]
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [OR,NC]
RewriteCond %{https} off
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
</IfModule>
Now all you have to do is to change example.com to your website address and you are all set
Bijay Pokharel
Related posts
Recent Posts
Subscribe
Cybersecurity Newsletter
You have Successfully Subscribed!
Sign up for cybersecurity newsletter and get latest news updates delivered straight to your inbox. You are also consenting to our Privacy Policy and Terms of Use.