How to get rid of the slash at the end of a URL with .htaccess?

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

Previous topic - Next topic

SHADOW_FANTOMTopic starter

My engine is a DLE.
Can you advise me on how to get rid of the slash at the end of a URL with .htaccess?
What should I put in the code?
I have experimented with different solutions, but now the behavior of the categories has changed when clicked.

Regarding website development, it's important to maintain clean and concise URLs for both user experience and search engine optimization. Utilizing techniques such as .htaccess can help achieve this goal. It's important to thoroughly test any modifications to avoid unexpected behavior.
  •  

chandanthaver

Please attempt the following code:
RewriteCond %{HTTP_HOST} (.*)
RewriteCond %{REQUEST_URI} /$ [NC]
RewriteRule ^(.*)(/)$ $1 [L,R=301]

If the solution doesn't work, please send me a private message with the file contents 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

To eliminate the trailing slash in a URL using the .htaccess file, try adding the following code:

Start with:
Rewrite Engine on
RewriteBase /

Then remove the slash (at least the final character of the address):
# removes trailing slash from address
RewriteCond %{REQUEST_URI} .+/$ [NC]
RewriteRule ^(.+)(/)$ $1 [L,R=301]

Alternatively, some may suggest (even for an empty address, which is not entirely accurate):
RewriteCond %{HTTP_HOST} (.*)
RewriteCond %{REQUEST_URI} /$ [NC]
RewriteRule ^(.*)(/)$ $1 [L,R=301]

Or experiments can be conducted with:
RewriteBase /
RewriteCond %{REQUEST_URI} /$ [NC]
RewriteRule ^(.*)(/)$ $1 [R=301,L]

In website development, it's essential to optimize URLs to be user-friendly and accessible to search engines. Utilizing best practices like these can aid in achieving those objectives, but it's critical to test thoroughly and monitor website analytics to track the impacts of any modifications.
  •