Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.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
Regex “合并”;文件夹作为获取参数";及;作为获取参数的子域";_Regex_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Regex “合并”;文件夹作为获取参数";及;作为获取参数的子域";

Regex “合并”;文件夹作为获取参数";及;作为获取参数的子域";,regex,apache,.htaccess,mod-rewrite,Regex,Apache,.htaccess,Mod Rewrite,我有一个站点,它将域后的路径重写为页面GET参数 ##REWRITING DIRECTORIES TO GET PARAMETERS RewriteBase / #Ignore all real directories (do not rewrite them) RewriteCond %{REQUEST_FILENAME} !-d #Also do not rewrite real files RewriteCond %{REQUEST_FILENAME} !-f #For everythin

我有一个站点,它将域后的路径重写为
页面
GET参数

##REWRITING DIRECTORIES TO GET PARAMETERS
RewriteBase /
#Ignore all real directories (do not rewrite them)
RewriteCond %{REQUEST_FILENAME} !-d
#Also do not rewrite real files
RewriteCond %{REQUEST_FILENAME} !-f
#For everything else, index.php should fetch the proper content
RewriteRule ^([^/]*)$ index.php?page=$1 [QSA,L]

##This means:
#example.com/help
#~becomes~
#example.com?page=help
该网站使用多种语言,到目前为止,我一直在使用cookies为用户设置和记住语言。虽然对用户的方便是有争议的,但这对用户来说绝对不方便

我需要将
[a-z]{2}\.mydomain\.xx
重写为
index.php?lang=$1
,这样用户就可以一直在
en.domain.com
上。有这样做的例子,但是我仍然对重写引擎如何工作感到困惑,我不知道应该如何将新规则与旧规则结合起来:

##Language rewrite
#Copypasted. Didn't understand
RewriteCond %{HTTP_HOST} ^([a-z]{1,2})\.domain\.xx
RewriteRule ([a-z]{1,2})\.domain\.xx index.php?lang=$1 [QSA,L]
如何获取
en.domain.com/help
上交
index.php?page=help&lang=en

如何在index.php中获取en.domain.com/help?page=help&lang=en

您可以使用:

RewriteEngine On
RewriteBase /

#Ignore all real directories (do not rewrite them)
RewriteCond %{REQUEST_FILENAME} !-d
#Also do not rewrite real files
RewriteCond %{REQUEST_FILENAME} !-f
#For everything else, index.php should fetch the proper content
RewriteCond %{HTTP_HOST} ^([a-z]{1,2})\.domain\.xx$ [NC]
RewriteRule ^([^/]+)/?$ index.php?lang=%1&page=$2 [QSA,L]

参考:你好,我终于测试了这个,但它不起作用。它实际上并没有重写任何东西-我在主页上被默认语言卡住了。。。此外,我怀疑当没有指定语言子域时,这将失败。这是在我的Apache上经过充分测试的规则。您在浏览器中输入的确切URL是什么?这是什么。htaccess位于哪里?在此之前还有更多的规则吗?我已经将
domain.xx
en.domain.xx
映射到localhost。我已将Apache配置为为此url创建虚拟主机。然后我输入了
http://en.domain.xx
。我用捷克语登上了主页。当我输入
http://en.domain.xx/contact
,出现英文主页。但是,如果我把你的规则一分为二,它就行了。实际上你可以稍微修改一下正则表达式,以匹配登录页,例如,
RewriteRule^([^/]*)/?$index.php?lang=%1&page=$2[QSA,L]
@anubhava请帮我回答这个问题:-)