将所有子域页面重定向到域页面
问题描述:
我有三个子域名,我想将所有子域名注册页面重定向到.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]
答
您需要[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]
答
在您的子域的注册页面,添加以下代码:
这不是PHP代码。这必须作为第一条规则放置在主要的.htacess文件中 – anubhava
我使用cloudflare,出于某种原因,这不起作用。我可以获得wp-config.php的代码吗? – sam
对不起,这个问题是基于.htaccess所以解决方案也是。什么网址无效,错误是什么?更好地展示你的完整.htaccess问题。 – anubhava