重定向整个Wordpress网站的良好做法

时间:2018-01-17 18:14:42

标签: wordpress .htaccess

我克隆了整个wordpress网站 - 让我们称之为x.com。我在新网站上安装了克隆 - 让我们打电话给y.com。

不,我需要在我的.htaccess中进行重定向。我试着用这个给了我500个内部错误:

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

RewriteEngine on 
RewriteRule ^(.*)$ http://y.com/$1 [R=301,L]

那么我如何正确地重定向x.com/product/cream重定向到y.com/product/cream等?

1 个答案:

答案 0 :(得分:1)

第一个块是导致Wordpress引擎处理各种URL的原因。您应该只在y.com的VirtualHost或.htaccess文件中使用此块,这是您现在托管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>

第二个块是重定向。您只想重定向x.com,因此请将此块仅放在x.com的VirtualHost或.htaccess文件中。

RewriteEngine on 
RewriteRule ^(.*)$ http://y.com/$1 [R,L]

请记住,仅在测试时使用临时重定向(302),因为浏览器会缓存永久重定向(301),导致浏览器在自己的缓存中查找结果而不是要求服务器进行新的重定向。如果您对结果感到满意,请将R更改为R=301,将规则更改为永久重定向。

相关问题