amir shariflou amir shariflou - 7 months ago 24
PHP Question

how to remove slash from url with htaccess

how to redirect trailing slash from URL i want remove slash from end and romove slash between FILENAME

url => http://localhost/
url => http://localhost/customer/
url => http://localhost/customer/account///login/
url => http://localhost/customer/account/login///register///


And after cleaning url

http://localhost
http://localhost/customer
http://localhost/customer/account/login
http://localhost/customer/account/login/register


this is code htaccess

RewriteEngine On
RewriteBase /

Options -Indexes
Options -MultiViews

# view only www
# RewriteCond %{HTTP_HOST} !^$
# RewriteCond %{HTTP_HOST} !^www\. [NC]
# RewriteCond %{HTTPS}s ^on(s)|
# RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

<Files ~ '^.ht'>
order allow,deny
deny from all
</Files>

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

# remove one slash
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.*?)/+(/[^\s]+) [NC]
RewriteRule ^ %1%2 [R=302,L,NE]
RewriteRule ^(.+?)/$ /$1 [R=302,NE,L]

RewriteRule ^(.*)$ /index.php?url=$1 [QSA,L]

Answer
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.*?)/+(/[^\s]+) [NC]
RewriteRule ^ %1%2 [R=302,L,NE]
RewriteRule ^(.+?)/$ /$1 [R=302,NE,L]

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

RewriteRule ^(.*)$ /index.php?url=$1 [QSA,L]