A
A
Andrei Birukou2020-09-07 14:09:41
htaccess
Andrei Birukou, 2020-09-07 14:09:41

How to remove slashes at the end of the URL and duplicate slashes if there are any in the middle through .htaccess?

Hello, I can not figure out how to remove the slashes at the end of the url.
The site works through the front controller, all requests are sent to index.php
Now .htaccess looks like this:

AddDefaultCharset utf-8

RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php

How to fix it so that if there is a slash at the end, it will redirect to the same URL without a slash at the end, or if
someone enters additional slashes in the middle, only 1 remains

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2020-09-07
@Rizzi

AddDefaultCharset utf-8

RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [R=301,L]

RewriteCond %{THE_REQUEST} ^[^?]+//
RewriteRule ^(.*)$ /$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php [L]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question