Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.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
.htaccess将没有语言子文件夹的域重定向到语言子文件夹_.htaccess_Redirect_Mod Rewrite - Fatal编程技术网

.htaccess将没有语言子文件夹的域重定向到语言子文件夹

.htaccess将没有语言子文件夹的域重定向到语言子文件夹,.htaccess,redirect,mod-rewrite,.htaccess,Redirect,Mod Rewrite,我有一个类似“domain.com”的域,现在我为语言创建子文件夹。 现在我的域有了这个子文件夹“domain.it/it/”和“domain.com/en/”。 我只需要将根域“domain.it”重定向到“domain.com/it/,我尝试在.htaccess中执行此操作,但出现了“太多重定向”: 这是: RewriteCond %{REQUEST_URI} !^/(en|it)/ RewriteRule ^(.*)$ https://www.domain.it/it/ [L,R=301]

我有一个类似“domain.com”的域,现在我为语言创建子文件夹。 现在我的域有了这个子文件夹“domain.it/it/”和“domain.com/en/”。 我只需要将根域“domain.it”重定向到“domain.com/it/,我尝试在.htaccess中执行此操作,但出现了“太多重定向”:

这是:

RewriteCond %{REQUEST_URI} !^/(en|it)/
RewriteRule ^(.*)$ https://www.domain.it/it/ [L,R=301]
我该怎么做?
谢谢

第一条规则+条件始终匹配,因此会导致无限循环。对于这种情况,您只需要一条规则:

RewriteRule ^(?!(?:it|en)/).* https://www.domain.it/it/$0 [L,R=301]
这使用了一个带有非捕获子模式的否定前瞻断言。但是,我建议您也添加另一个规则(在该规则之前)以帮助手动输入/复制不良的URL:

RewriteRule ^(?:it|en)$ https://www.domain.it/$0/ [L,R=301]
RewriteRule ^(?:it|en)$ https://www.domain.it/$0/ [L,R=301]