【发布时间】:2015-02-04 12:36:23
【问题描述】:
我知道很多其他关于 htaccess 重定向的问题,但找不到任何似乎在我的特定场景中有效的东西。
我在www.oldsite.com.au/wp-subdir 安装了一个wordpress 网站。该站点使用永久链接,因此/wp-subdir/.htaccess 文件中包含以下内容:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wp-subdir/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wp-subdir/index.php [L]
</IfModule>
# END WordPress
在设置页面上,“WordPress 地址 (URL)”和“站点地址 (URL)”都设置为 http://www.oldsite.com.au/wp-subdir - 也就是说,该站点没有被呈现为好像它存在于根目录中一样 - 一个选项在Giving wordpress its own directory 上解释
法典页面)
我已将此站点复制到www.newsite.com.au/wp-subdir,但这里是按照上述法典设置的。即在该域的设置页面中,“WordPress 地址(URL)”设置为http://www.newsite.com.au/wp-subdir,“站点地址(URL)”设置为http://www.newsite.com.au。
这两个网站在隔离时都运行良好。
但是,现在我希望将旧网站上的所有点击重定向到新网站上的类似位置。
我想要的示例
http://www.oldsite.com.au/wp-subdir -> http://www.newsite.com.au
http://www.oldsite.com.au/wp-subdir/products -> http://www.newsite.com.au/products
http://www.oldsite.com.au/wp-subdir/images/imagePermaLink -> http://www.newsite.com.au/images/imagePermaLink
http://www.oldsite.com.au/wp-subdir/?s=search+terms -> http://www.newsite.com.au/?s=search+terms(显示搜索结果页面)
http://www.oldsite.com.au/wp-subdir/unknown-page -> http://www.newsite.com.au/unknown-page(显示404页)
来自 google 图片结果的链接 -> http://www.newsite.com.au/images/imagePermaLink
我的尝试
将 .htaccess 文件添加到
www.oldsite.com.au的根目录,使用Redirect 301 /wp-subdir http://www.newsite.com.au/-
在根 .htaccess 文件中使用它:
Options +FollowSymlinks -MultiViews RewriteBase / RewriteEngine On RewriteCond %{HTTP_HOST} ^(www\.)+oldsite\.com\.au [NC] RewriteRule ^wp-subdir/(.*) http://www.newsite.com.au/ [R=301,NC,L] 将
oldsite.com.au/wp-subdir/.htaccess(之前完整列出)的重写规则从:RewriteRule . /wp-subdir/index.php [R=301,L]
到:
RewriteRule . www.newsite.com.au/index.php [R=301,L]
所有更改(单独)都会导致以下情况:
http://www.oldsite.com.au/wp-subdir -> http://www.newsite.com.au 通过
http://www.oldsite.com.au/wp-subdir/products -> http://www.newsite.com.au 失败
http://www.oldsite.com.au/wp-subdir/images/imagePermaLink -> 找不到页面错误(不是网站的 404 模板)FAIL
http://www.oldsite.com.au/wp-subdir/?s=search+terms -> http://www.oldsite.com.au/wp-subdir/?s=search+terms 失败
http://www.oldsite.com.au/wp-subdir/unknown-page -> http://www.newsite.com.au 失败
来自 google 图片结果的链接 -> http://www.newsite.com.auimages/imagePermaLink(域名后缺少斜杠)FAIL
如果还不是很明显,我对 .htaccess 文件了解甚少......所以任何帮助表示赞赏!
编辑:
今天早上用我的 iPad 再看一遍,结果发现我上面的选项 1 确实有效。现在再次在我的笔记本电脑上它(几乎*)也可以正常工作。也许我的笔记本电脑上的某些浏览器缓存导致以前的重定向尝试被记住。
*在 Chrome 中,某些页面在重定向后显示正常,但选项卡上的页面加载旋转轮图标永远不会完成(并且使用开发人员工具,网络和时间线选项卡没有数据)。
*在 Chrome 中,来自 google 图片搜索的重定向在主机后仍然缺少斜杠。
【问题讨论】:
标签: wordpress .htaccess redirect