Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.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
Wordpress apache301将rewrite/to/en和keep/fr重定向到/fr,保留所有传递的变量_Wordpress_Apache_Mod Rewrite_Redirect_Multilingual - Fatal编程技术网

Wordpress apache301将rewrite/to/en和keep/fr重定向到/fr,保留所有传递的变量

Wordpress apache301将rewrite/to/en和keep/fr重定向到/fr,保留所有传递的变量,wordpress,apache,mod-rewrite,redirect,multilingual,Wordpress,Apache,Mod Rewrite,Redirect,Multilingual,我有一个双语Wordpress网站,我正在改变域名,下面的重定向非常有效 RewriteEngine on RewriteCond %{HTTP_HOST} !^newdomain\.com$ RewriteRule ^ http://newdomain.com%{REQUEST_URI} [L,R=301] 问题是我想要 olddomain.com/one/two/three 重定向到 newdomain.com/en/one/two/three 但是保持 olddomain.com

我有一个双语Wordpress网站,我正在改变域名,下面的重定向非常有效

RewriteEngine on
RewriteCond %{HTTP_HOST} !^newdomain\.com$
RewriteRule ^ http://newdomain.com%{REQUEST_URI} [L,R=301]
问题是我想要

olddomain.com/one/two/three 
重定向到

newdomain.com/en/one/two/three 
但是保持

olddomain.com/fr/one/two/three
重定向到

newdomain.com/fr/one/two/three

您可以将此规则放置在主WP.htaccess中的
RewriteBase
行下方:

RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^en/ http://newdomain.com%{REQUEST_URI} [L,NE,R=301]

RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule !^(en|fr)/ http://newdomain.com/fr%{REQUEST_URI} [L,NE,R=301]

一/二/三只是一个例子。它将永远是不同的。我真的很需要一个“如果还有”。如果是英语,就去英语,如果不是英语,就去法语。domain.com/en/year/month/postname应该转到newdomain.com/en/year/month/postname,否则如果domain.com/year/month/postname(无en)则重定向到newdomain.com/fr/year/month/postname年/月/postname只是一个例子,我希望这项工作适用于所有页面、帖子类别等。很高兴它成功了。规则1匹配以
/en/
开头并重定向到
http://newdomain.com/URI
而规则2匹配任何不是
/en/
/fr/
的内容,并重定向到
http://newdomain.com/fr/URI
谢谢。我看了很久才明白其中的道理。习惯于在“重写条件”中查看条件,而不是“重写规则”