多语言网站,子目录语言(重写规则)子目录、重写、多语言、规则

2023-09-02 00:46:33 作者:伴人一霎

有关我的网站,我想重写我的网址为:

For my website i want to rewrite my url to:

www.xxx.com/en/index.php代替www.xxx.com/index.php?language=en   而不是www.xxx.com/index.php?language=nl www.xxx.com/nl/index.php

www.xxx.com/en/index.php instead of www.xxx.com/index.php?language=en www.xxx.com/nl/index.php instead of www.xxx.com/index.php?language=nl

www.xxx.com应www.xxx.com/en~~V /

www.xxx.com should be www.xxx.com/en/

这实际工作我已经添加了这些重写规则

This actually works i have added these rewrite rules

的RewriteCond%{HTTP_HOST}%{REQUEST_URI} ^ WWW .XXX .COM( /?)$ 重写规则(。*) http://www.xxx.com/en/ $ 1 [R = 302,L] 重写规则^(NL | EN)/ $ $ 2语言= $ 1安培(*);?%{QUERY_STRING} [L] 在R = 302添加用于测试目的

RewriteCond %{HTTP_HOST}%{REQUEST_URI} ^www.xxx.com(/?)$ RewriteRule (.*) http://www.xxx.com/en/$1 [R=302,L] RewriteRule ^(nl|en)/(.*)$ $2?language=$1&%{QUERY_STRING} [L] The R=302 is added for testing purposes

是上面给出的RewriteCond和重写规则不够好,或有其他的,也许更短或更好的方法来重写的.com /以.COM / EN /

Are the above given RewriteCond and RewriteRule good enough or are there other, maybe shorter or better ways to rewrite .com/ to .com/en/

如果该URL被编辑到不存在,我想这个用户是重定向到英语的语言。

If the url is edited to a language that does not exists i want this user to be redirect to english.

示例 www.xxx.com/es/index.php要求,这种语言不存在,或没有语言给出我希望用户被重定向到www.xxx.com/en/index.php~~V

Example www.xxx.com/es/index.php is requested, this language does not exists or no language is given i want the user to be redirect to www.xxx.com/en/index.php

我试过如下: 重写规则^([^ N] [^ L] | [^ E] [^ N])(。*)/ $ EN / $ 2%{QUERY_STRING} [L,R = 302]

I tried the following: RewriteRule ^([^n][^l]|[^e][^n])/(.*)$ en/$2%{QUERY_STRING} [L,R=302]

此工作在一些情况下,但如果www.xxx.com/ne/index.php输入它被认为是有效的,而不是重写。 www.xxx.com/index.php也没有改写为www.xxx.com/en/index.php~~V

This works in some cases but if www.xxx.com/ne/index.php is entered it is considered as valid and not rewritten. www.xxx.com/index.php is also not rewritten to www.xxx.com/en/index.php

有人能帮助我解决这个问题?

Could someone help me to fix this?

在此先感谢!

推荐答案

试试这个规则:

RewriteCond $1 !^(en|nl)$
RewriteRule ^([a-z]{2})/(.*)$ en/$2 [L,R=302]