Hello everyone, I registered such lines in .htaccess

RewriteEngine on RewriteCond %{REQUEST_URI} !^/en/ RewriteCond %{REQUEST_URI} !^/ru/ RewriteRule ^(.*)$ http://127.0.0.1/en/$1 [L,R=301] 

everything works as it should, but here it is also necessary that for example, if the user entered in the address line 127.0.0.1/en (without a backslash) the slash is automatically added to the address line, how to do it?

127.0.0.1/en/ everything works

127.0.0.1/en when typing in the address bar goes like 127.0.0.1/en/en

    2 answers 2

    There are 2 solutions.

    1. Change the RewriteCond condition to prevent processing requests of the host / language type.

     RewriteEngine on RewriteCond %{REQUEST_URI} !^/(en|ru)(/|$) RewriteRule ^(.*)$ http://127.0.0.1/en/$1 [L,R=301] 

    Pay attention to the $ symbol in the RewriteCond condition, it is needed so that requests like / enterprise are not discarded, but are reduced to the form / en / enterprise.

    2. Adding a slash to a query of the form host / language.

     RewriteEngine on RewriteRule ^/(en|ru)$ /$1/ [L,R=301] RewriteCond %{REQUEST_URI} !^/(en|ru)/ RewriteRule ^(.*)$ http://127.0.0.1/en/$1 [L,R=301] 

    The first rewriteRule adds a slash.

    Which option should I choose?

    It makes sense to use the second option if the server has a difference between the / en and / en / requests, for example, a proxy can be configured for the en directory. Otherwise, I would choose the first option as a more compact and non-repetitive "en | ru".

      It was decided, it was necessary to add another exception for the folder / en (without a slash)

       RewriteEngine on RewriteCond %{REQUEST_URI} !^/en/ RewriteCond %{REQUEST_URI} !^/en //вот что добавил RewriteCond %{REQUEST_URI} !^/ru/ RewriteCond %{REQUEST_URI} !^/ru //вот что добавил RewriteRule ^(.*)$ http://127.0.0.1/en/$1 [L,R=301]