问题描述
我最近为我的WordPress网站购买了一个新域,我想将使用旧域访问的任何人重定向到新域。我还没有移动服务器,只是添加了一个新域。
I recently purchased a new domain for my WordPress site and I want to redirect anyone who visits using an old domain to the new one. I haven't moved servers, just added a new domain.
例如,如果它们去了以下任意一个:
For instance, if they went to either of these:
http://www.example.net/some-article/
http://example.net/some-article/
然后我希望将它们重定向到适当的URL:
Then I'd like them to be redirected to the appropriate URL:
http://www.example.com/some-article/
http://example.com/some-article/
如何使用.htaccess文件重定向这个简单的.net-> .com?任何规则都应适用于.net域下的所有URL。
How would you do this simple .net -> .com redirect with a .htaccess file? Any rule should apply to all URLs under the .net domain.
请先感谢。
编辑::我已经在服务器上安装了.htaccess文件:
I already have the .htaccess file on the server:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
AddHandler php5-script .php
推荐答案
您需要向.htaccess文件中添加以下命令:
You need to add commands like this to your .htaccess file:
重定向永久/ some-article / a href = http://www.example.com/some-article/ rel = noreferrer> http://www.example.com/some-article/
redirect permanent /some-article/ http://www.example.com/some-article/
这是具有mod_rewrite的服务器吗?在这种情况下,您可以对所有路径进行通用重定向:
Is this a server with mod_rewrite? In this case you could do a generic redirection for all paths:
RewriteEngine On
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301]
这篇关于使用.htaccess从一个域重定向到另一个域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!