mod_rewrite语言参数
问题描述:
I'm looking to use the language switch in our website using mod rewrite. Instead of showing:
https://www.website.com/rest/of/my-site?lang=it
https://www.website.com/en/rest/of/my-site
The problems comes here. A Our current mod rewrite configuration:
# General rewrites
RewriteRule -p([0-9]+)\.html$ index.php?module=page&id=$1&%{QUERY_STRING} [L]
RewriteRule (news|nieuws)/(.*)\.html$ index.php?module=news&url_raw=$2&%{QUERY_STRING} [L]
RewriteRule (.*)\.html$ index.php?module=page&url_raw=$1&%{QUERY_STRING} [L]
#rewriteRule contact(/|)$ index.php?module=contact&%{QUERY_STRING} [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*)$ index.php?module=page&url_raw=$1&%{QUERY_STRING} [L]
B Mod rewrite and the PHP snippet When the mod rewrite is working the user should be able to switch from
- website.com/en/rest/of/my-site
- website.com/it/rest/of/my-site
Instead of
- website.com/en/rest/of/my-site?lang=it
I have tried several options (language parameter rewrite with mod_rewrite) but I do not come far enough with it.
我希望使用mod重写在我们的网站中使用语言切换。 而不是显示: p>
https://www.website.com/rest/of/my-site?lang=it
https://www.website.com/ en / rest / of / my-site
code> pre>
问题来自这里。
我们当前的mod重写配置: p>
#General rewrites
RewriteRule -p([0-9] +)\。html $ index.php?module = page& id = $ 1&%{QUERY_STRING} [L]
RewriteRule(news | nieuws)/ (。*)\。html $ index.php?module = news& url_raw = $ 2&%{QUERY_STRING} [L]
RewriteRule(。*)\。html $ index.php?module = page& url_raw = $ 1& ;%{QUERY_STRING} [L]
#rewriteRule contact(/ |)$ index.php?module = contact&%{QUERY_STRING} [L]
RewriteCond%{REQUEST_FILENAME}!-f
RewriteCond%{REQUEST_FILENAME} !-d
RewriteRule(。*)$ index.php?module = page& url_raw = $ 1&%{QUERY_STRING} [L]
code> pre>
B Mod重写 和mod片段
当mod重写工作时,用户应该能够从 p>
- website.com/en/rest/of/my-site LI>
- website.com/it/rest/of/my-site LI>
UL>
Inste 广告 p>
- website.com/en/rest/of/my-site?lang=it li>
ul>
我尝试了几个选项(使用mod_rewrite重写语言参数)但是我 用它来做得不够。 p>
div>
答
Try adding this to the top of your rules:
RewriteCond %{THE_REQUEST} \ /+(.*)\?(.*?)&?lang=([^&\ ]+)([^\ ]*)
RewriteRule ^ /%3/%1?%2%4 [L,R]
RewriteCond %{QUERY_STRING} !(^|&)lang=
RewriteRule ^([a-z][a-z])/(.*)$ /$2?lang=$1 [L,QSA]