E
E
Evgeny Efimchenko2018-09-11 18:52:05
htaccess
Evgeny Efimchenko, 2018-09-11 18:52:05

How to remove first slash after URL?

Good time of the day.
I am using PHP routing.
htaccess:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?route=$1 [B,L,QSA]
And I can't get rid of double (triple, etc.) e.) slash right after the site address.
For example site.ru/article////page/5 in GET['route'] we get article////page/5 and the router will redirect to site.ru/article/page/5
But site.ru// //article/page/5 It won't redirect anywhere, since the GET['route'] parameter will contain article/page/5 and, accordingly, there will be no redirection.
No one will help with advice.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
dodo512, 2018-09-12
@clean_code

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

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?route=$1 [B,L,QSA]

D
Dmitry, 2018-09-11
@By_Engine

If the user himself drives a URL with all sorts of garbage into the address bar, then he needs to wring his hands to give an error 404

D
Dom Alfro, 2018-09-11
@mustang_shelby

you can do a check in index.php for example - use the trim functions (many different videos about this)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question