使用htaccess重定向Wordpress网站

时间:2015-07-30 14:56:24

标签: wordpress .htaccess redirect

情况

数据存储在http://aplhazone.myserver.com

域名为http://betazone.com,其中可能是CNAME记录(我无法访问服务器配置)。

这是WordPress有自己的htaccess:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
# END WordPress

期望的行为

将所有流量(可能为301)从http://aplhazone.myserver.comhttp://www.betazone.com重定向到http://betazone.com

尝试失败

案例一

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.betazone.com$ [OR]
RewriteCond %{HTTP_HOST} ^aplhazone.myserver.com$
RewriteRule ^(.*)$ http://betazone.com/$1 [R=301,L]

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>

# END WordPress

案例二

Redirect 301 / http://betazone.com/

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>

# END WordPress

常见错误

第一

The page isn't redirecting properly

Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

    This problem can sometimes be caused by disabling or refusing to accept cookies.

第二

The page isn't redirecting properly Firefox has detected that the server is redirecting the request for this address in a way that will never complete. This problem can sometimes be caused by disabling or refusing to accept cookies

第三

Charles Error Report
Failed to connect to remote host

Charles failed to connect to the remote host. Check that your Internet connection is ok and that the remote host is accessible. Maybe your network uses a proxy server to access the Internet? You can configure Charles to use an external proxy server in the External Proxy Settings.

The actual exception reported was:

java.net.ConnectException: Connection timed out: connect

Charles Proxy, http://www.charlesproxy.com/ 

我做错了什么?

1 个答案:

答案 0 :(得分:1)

尝试以下

RewriteEngine On
RewriteCond %{HTTP_HOST} !^betazone\.com [NC]
RewriteRule (.*) http://betazone.com/$1 [R=301,L]

重写条件规定如果主机名不是以betazone.com开头,则重定向到betazone.com。因此www.betazone.com和alphazone.myserver.com将被重定向到betazone.com