Reputation: 11265
What I want to achieve:
http://example.com/en -> http://example.com/?lang=en
http://example.com/en/something -> http://example.com/something/?lang=en
http://example.com/ru -> http://example.com/?lang=ru
http://example.com/ru/something -> http://example.com/something/?lang=ru
I try with:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^en/(.+)$ /?p=$1&lang=en [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ru/(.+)$ /?p=$1&lang=ru [L,QSA]
Upvotes: 1
Views: 60
Reputation: 22821
You can do it like this:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(ru|en)/(.+)$ /$2/?lang=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(ru|en)/?$ /?lang=$1 [L,QSA]
(ru|en)
will match either ru
or en
. If you wanted to make it a generic 2 letter match, you could use [a-z]{2}
Upvotes: 1