【发布时间】:2016-12-13 01:34:33
【问题描述】:
我将一个 wordpress 网站移至另一个域。但是,我想保留谷歌链接并帮助它重新索引新站点。
我做了一个 301 重定向,但它只适用于根目录。当有人去http://oldsite.com/directory/post-name-here/时,我希望他们被转发到http://newsite.com/directory2/post-name-here/。这两个网站都在子目录中。有没有办法在 PHP 中做到这一点?或者我需要一个mod-rewrite吗?
最终对我有用的是:
我的旧站点文件结构是这样的:
/public_html/
index.php
/development/
.htaccess
回顾一下,我想将进入开发目录的所有内容转发到新网站。这是development 目录中.htaccess 的代码。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^oldsite.org$ [OR]
RewriteCond %{HTTP_HOST} ^www.oldsite.org$
RewriteRule (.*)$ http://newsite.com/newdirectory/$1 [R=301,L]
非常感谢彼得
【问题讨论】:
标签: wordpress .htaccess redirect mod-rewrite