Saturday , February 22 2025

301 redirect from slash to without slash

Examples of redirects from pages with a slash to without a slash:

Example 1 – 301 redirect from slash to without slash

RewriteCond %{REQUEST_URI} !\?
RewriteCond %{REQUEST_URI} !\&
RewriteCond %{REQUEST_URI} !\=
RewriteCond %{REQUEST_URI} !\.
RewriteCond %{REQUEST_URI} ![^\/]$
RewriteRule ^(.*)\/$ /$1 [R=301,L]

If your site uses a CMS (for example, Opencart), then after adding the above conditions to .htaccess, the admin panel will stop working. Because it is necessary for the admin panel not to use a redirect from slash to without slash.

Example 2 – 301 redirect from slash to without slash (except admin panel)

RewriteCond %{REQUEST_URI} !\?
RewriteCond %{REQUEST_URI} !\&
RewriteCond %{REQUEST_URI} !\=
RewriteCond %{REQUEST_URI} !\.
RewriteCond %{REQUEST_URI} !^/admin/.*$
RewriteCond %{REQUEST_URI} ![^\/]$
RewriteRule ^(.*)\/$ /$1 [R=301,L]

About iryna

I'm Iryna, a web developer from Ukraine with a decade of experience solving complex technical challenges in the world of freelance. Throughout my career, I've worked on everything from troubleshooting server-side issues and optimizing website performance to enhancing user interfaces. On this blog, I share detailed solutions to the technical problems I’ve encountered and methods that have worked best for me. In addition to my technical expertise, I’m also passionate about digital drawing. I hope the tutorials and insights I provide here will help both fellow developers and creatives alike in their own projects.

Check Also

How to find changed files in console

Relevant for Linux, macOS. This article lists commands that help you find files that have …

Leave a Reply

Your email address will not be published. Required fields are marked *