Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/242.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php modrewrite语言参数_Php_.htaccess_Mod Rewrite_Switch Statement - Fatal编程技术网

Php modrewrite语言参数

Php modrewrite语言参数,php,.htaccess,mod-rewrite,switch-statement,Php,.htaccess,Mod Rewrite,Switch Statement,我期待在我们的网站上使用mod rewrite的语言开关。而不是显示: https://www.website.com/rest/of/my-site?lang=it https://www.website.com/en/rest/of/my-site 问题来了。 A我们当前的mod rewrite配置: # General rewrites RewriteRule -p([0-9]+)\.html$ index.php?module=page&id=$1&%{QUERY_ST

我期待在我们的网站上使用mod rewrite的语言开关。而不是显示:

https://www.website.com/rest/of/my-site?lang=it
https://www.website.com/en/rest/of/my-site
问题来了。 A我们当前的mod rewrite配置:

# 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和PHP代码段 当mod rewrite工作时,用户应该能够从

  • website.com/en/rest/of/my-site
  • website.com/it/rest/of/my-site
而不是

  • website.com/en/rest/of/my site?lang=it

我尝试了几个选项(),但我做得还不够。

尝试将此添加到规则的顶部:

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]

如果不是其他语言环境,请求是否总是指向website.com/en?这意味着,我们可以依赖第一个文件夹代表区域设置这一事实吗?是的,这是正确的。Al/en、/it等都指向同一个文件夹。工作起来像个符咒!:)