Friday , December 20 2024

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 admin

Hi there! My name is Iryna, I am a web developer from Ukraine. While working on freelance projects I often face different technical issues and in this blog I publish articles on how to solve them. I am also interested in digital drawing and in this blog you will find brief tutorials that helped me and hopefully can help you as well.

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 *