2016-01-22 159 views
0

我有三個子域名,我想將所有子域名註冊頁面重定向到.htaccess中的域註冊頁面,用於wordpress多站點。我正在使用下面的代碼,但它不起作用。將所有子域頁面重定向到域頁面

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^sub\.domain1\.com$ 
RewriteCond %{HTTP_HOST} ^sub\.domain2\.com$ 
RewriteCond %{HTTP_HOST} ^sub\.domain3\.com$ 
RewriteRule ^register/(.*)$ http://domain.com/register/$1 [R=301,L] 

回答

0

您需要[OR]條件,使這項工作,否則你的條件,因爲HTTP_HOST總是失敗不能等於在同一時間所有的3子域:

RewriteEngine On 

RewriteCond %{HTTP_HOST} ^sub\.domain1\.com$ [OR] 
RewriteCond %{HTTP_HOST} ^sub\.domain2\.com$ [OR] 
RewriteCond %{HTTP_HOST} ^sub\.domain3\.com$ 
RewriteRule ^register/(.*)$ http://domain.com/register/$1 [R=301,L] 

另一個短的方式:

RewriteCond %{HTTP_HOST} ^(sub\.domain1\.com|sub\.domain2\.com|sub\.domain3\.com)$ [NC] 
RewriteRule ^register/(.*)$ http://domain.com/register/$1 [R=301,L] 
+0

這不是PHP代碼。這必須作爲第一條規則放置在主要的.htacess文件中 – anubhava

+0

我使用cloudflare,出於某種原因,這不起作用。我可以獲得wp-config.php的代碼嗎? – sam

+0

對不起,這個問題是基於.htaccess所以解決方案也是。什麼網址無效,錯誤是什麼?更好地展示你的完整.htaccess問題。 – anubhava

0

在您的子域的註冊頁面,添加以下代碼:

​​
相關問題