2014-09-19 61 views
0

我已要求我的域名托管服务商将网站指向我的public_html文件夹。但现在我被告知,如果我需要这个其他域重定向到我的主域网站上的特定网址,我需要在htaccess文件中执行此操作。目前我已经研究过,这是我的htaccess看起来没有任何运气!htaccess外部域名到新域名

# Switch rewrite engine off in case this was installed under HostPay. 
RewriteEngine Off 

SetEnv DEFAULT_PHP_VERSION 5 

DirectoryIndex index.cgi index.php 

# 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 

RewriteCond %{HTTP_HOST} ^otherdomain.org.uk 
RewriteRule ^(.*)$ http://www.primarydomain.org/blog/$1 [R=permanent,L] 

上面没有将我的otherdomain.org.uk重定向到我的primarydomain.org/blog上的博客页面。请注意,我的primarydomain.org/blog是一个wordpress网站页面。

+0

你需要在'otherdomain.org.uk'服务器的'DocumentRoot'文件夹重定向规则。 – anubhava 2014-09-19 19:03:01

+0

otherdomain.org.uk指向primarydomain.org的htaccess文件所在的同一个public_html文件夹。目前otherdomain.org.uk重定向到primarydomain.org,但不是primarydomain.org/blog/ – user3214892 2014-09-19 19:11:22

+0

请不要这是一个WordPress的页面,所以URL并不真实反映在文档文件夹 – user3214892 2014-09-19 19:21:58

回答

1

保持您的WP规则之前的重定向规则。

让你的规则是这样的:

# Switch rewrite engine off in case this was installed under HostPay. 
RewriteEngine Off 

SetEnv DEFAULT_PHP_VERSION 5 

DirectoryIndex index.cgi index.php 

# BEGIN WordPress 
<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/

RewriteCond %{HTTP_HOST} ^otherdomain.org.uk 
RewriteRule ^(.*)$ http://www.primarydomain.org/blog/$1 [R=permanent,L] 

RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
</IfModule> 

# END WordPress 
+0

我刚试过没有运气。 otherdomain.org.uk仍然会重定向到primarydomain.org,但不会返回到博客页面 – user3214892 2014-09-19 19:27:11

+0

您是否在新浏览器中对其进行了测试?在Firebug中打开这个UR并在Net标签下看到你有多少个重定向? – anubhava 2014-09-19 19:29:40

+0

我对Firebug不熟悉。我尝试在另一个浏览器中,仍然不做什么htaccess的意图 – user3214892 2014-09-19 20:02:00