简体   繁体   English

.htaccess复杂的mod_rewrite规则,URL中的语言

[英].htaccess complex mod_rewrite rule, language in URL

I would like to write a rule, that would redirect URL like this: 我想写一条规则,将这样重定向URL:

myweb.com/en/page

to

myweb.com/page.php?lang=en

And URL like this 和这样的网址

myweb.com/en/page/SOME_TEXT(EVEN WITH SLASHES)

to

myweb.com/page.php?lang=en&string=SOME_TEXT

This code: 这段代码:

RewriteRule ^(cz|en)/(.*)$  $2?lang=$1 [QSA,L]

works for the language but not for the another text (SOME_TEXT). 适用于该语言,但不适用于其他文本(SOME_TEXT)。

What should I change? 我应该改变什么? Thanks everyone. 感谢大家。

Try the following: 请尝试以下操作:

RewriteRule ^/(cz|en)/(.*)$  $2.php?lang=$1 [L]
RewriteRule ^/(cz|en)/([^/]+)/(.*)$  $2.php?lang=$1&string=$3 [L]

You can use the following : 您可以使用以下内容:

RewriteRule ^/?(cz|en)/([^/]+)/?(.*)$  $2.php?lang=$1&string=$3 [QSA,L]

?: is used to disable the capture group, so $1 now Contains the value of your second capture group. ?:用于禁用捕获组,因此$ 1现在包含第二个捕获组的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM