J
J
justyork2016-07-06 18:29:22
htaccess
justyork, 2016-07-06 18:29:22

How to set language prefix in htaccess?

Hello everyone, please tell me how to set up htaccess so that if the url does not start with a language, then it will default to en. Here's what I googled, but it doesn't work for me.

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

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
justyork, 2016-07-07
@justyork

I solved the problem myself, maybe there is something superfluous, but in general it works.

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

RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

RewriteCond %{REQUEST_URI} !^/(?:ru|en|gr)/
RewriteRule ^([^/]+(/.*)?)$ /en/$1 [R=301,L]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question