How to remove slash at the end of URL using .htaccess?

Started by SHADOW_FANTOM, Aug 28, 2022, 09:41 AM

Previous topic - Next topic

SHADOW_FANTOMTopic starter

I have a dle engine
How to remove slash at the end of URL using .htaccess?
What should be written there?
Tried everything, now it's different when I click on categories.
  •  

chandanthaver

try
RewriteCond %{HTTP_HOST} (.*)
RewriteCond %{REQUEST_URI} /$ [NC]
RewriteRule ^(.*)(/)$ $1 [L,R=301]

If it doesn't work, PM what you got in the file and website url.
  •  

Sumpi Bi

Try to delete like this

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} (.*)
RewriteCond %{REQUEST_URI} /$ [NC]
RewriteRule ^(.*)(/)$ $1 [L,R=301]


If you need to do it back, then do a redirect:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*[^/])$ $1/ [L,R=301]
  •  
    The following users thanked this post: Sevad

rafiazafar

You can remove the slash like this, write something like this in the .htaccess file:
At the beginning of the file you should have:

Rewrite Engine on
RewriteBase /

And then, actually getting rid of the slash (at least one address character):

# remove the slash at the end of the address
RewriteCond %{REQUEST_URI} .+/$ [NC]
RewriteRule ^(.+)(/)$ $1 [L,R=301]

Or as they say on the net (any address is even empty, which is not entirely accurate:

RewriteCond %{HTTP_HOST} (.*)
RewriteCond %{REQUEST_URI} /$ [NC]
RewriteRule ^(.*)(/)$ $1 [L,R=301]

Or experiment with this:

RewriteBase /
RewriteCond %{REQUEST_URI} /$ [NC]
RewriteRule ^(.*)(/)$ $1 [R=301,L]
  •