Redirect URL terminated with multiple bars to the same URL with a single bar

2

It turns out I made a redirection to my web so that it redirected the url without a bar to the url with a bar as long as it was not a file.

# si no existe un archivo que coincida con la solicitud...
RewriteCond %{REQUEST_FILENAME} !-f
# y si no termina con una barra, redireccionar a la misma dirección pero con la barra
RewriteRule ^(.*[^/]$) $1/ [R,QSA,L]

I found it on this page, but now I want that if you try to access the url with several bars, also redirect to the same url with a single bar.

Example:

www.mipagina.com/categoria/articulo-numero-201////

redirect to

www.mipagina.com/categoria/articulo-numero-201/
    
asked by Andrew Herrera 05.04.2018 в 21:07
source

1 answer

2

One would think that it would be done with a RewriteRule that matches // . However, Apache eliminates redundant bars by passing them to the .htaccess. Therefore, we have to compare to %{REQUEST_URI} (which has the original request).

RewriteEngine on
RewriteBase /

# redireccionar si tiene 2 o más "/"
RewriteCond %{REQUEST_URI} //
# a la URL sin barras redundantes (Apache las elimina)
RewriteRule ^(.*?)/*$ $1/ [R=301,L]


# si no existe un archivo que coincida con la solicitud...
RewriteCond %{REQUEST_FILENAME} !-f
# y si no termina con una barra, redireccionar a la misma dirección pero con la barra
RewriteRule ^.*[^/]$ $0/ [R=301,L]


Demos (I went to a free hosting):

answered by 07.04.2018 в 08:31