问题
If you have a multilingual site like this:
example.com/en/some-folder/some-file
example.com/ru/some-folder/some-file
example.com/et/some-folder/some-file
Would it be possible to catch the "ru","en" and "et" into a PHP variable like $lang, and, at the same time, have a directory that looks like this using only htaccess?
htdocs/some-folder/some-file.php
Instead of:
htdocs/en/some-folder/some-file.php
htdocs/ru/some-folder/some-file.php
htdocs/et/some-folder/some-file.php
I want to be able to not have to re-create all folders and files for each of the languages. But I also want to catch the language in the URL into a variable, and and ignore it as if it does not exist.
回答1:
You can use that in your .htaccess
:
RewriteEngine on
RewriteRule ^(en|ru|et)(/.*)$ $2?lang=$1 [NC,L,QSA]
Rewrite example.com/en/some-folder/some-file.php
to example.com/some-folder/some-file.php?lang=en
来源:https://stackoverflow.com/questions/33585428/htaccess-skip-first-folder