简体   繁体   English

301使用新URL重定向Wordpress

[英]301 Redirect for Wordpress with New URL

We used the Wordpress Move plugin to migrate our Wordpress site from blog.ourdomain.com to www.ourdomain.com/blog and we cannot get a 301 redirect working. 我们使用Wordpress Move插件将我们的Wordpress网站从blog.ourdomain.com迁移到www.ourdomain.com/blog,我们无法获得301重定向工作。 Here is our full process ... 这是我们的全部流程......

  1. Made a copy of the file folder for the wordpress site as 'blog.ourdomain.com - Copy' 将wordpress网站的文件夹副本设为'blog.ourdomain.com - Copy'
  2. Used the Wordpress Move plugin to change the URL from blog.ourdomain.com to www.ourdomain.com/blog. 使用Wordpress Move插件将URL从blog.ourdomain.com更改为www.ourdomain.com/blog。
  3. Using IIS, created 'blog' as a virtual directory under ourdomain.com which pointed to the existing 'blog.ourdomain.com' folder. 使用IIS,将“blog”创建为ourdomain.com下的虚拟目录,该目录指向现有的“blog.ourdomain.com”文件夹。

... at this point, the new site was working correctly ... ......此时,新网站工作正常......

  1. Using IIS, pointed requests for blog.ourdomain.com to the 'blog.ourdomain.com - Copy' so that we could mess around with the htaccess and web.config folders without affecting the live site. 使用IIS,将blog.ourdomain.com的请求指向'blog.ourdomain.com - Copy',以便我们可以使用htaccess和web.config文件夹,而不会影响实时网站。
  2. We tried several different 301 combinations in the htaccess file but nothing seems to work. 我们在htaccess文件中尝试了几种不同的301组合,但似乎没有任何效果。 We also tries using IIS for the redirect, which did work, but we could not get it to use the dynamic URL and redirect to the correct page. 我们还尝试使用IIS进行重定向,这确实有效,但我们无法使用动态URL并重定向到正确的页面。

Here is an example of what we need: 以下是我们需要的示例:

OLD URL http://blog.ourdomain.com/2017/03/orientation-packages-for-new-employees/ 旧URL http://blog.ourdomain.com/2017/03/orientation-packages-for-new-employees/

Needs a 301 redirect to: http://www.ourdomain.com/blog/2017/03/orientation-packages-for-new-employees/ 需要301重定向到: http//www.ourdomain.com/blog/2017/03/orientation-packages-for-new-employees/

Perhaps the sub-directory is the part that is messing us up but we're not having any success using htaccess at all, not even redirects to the wrong URL. 也许子目录是弄乱我们的部分,但我们根本没有成功使用htaccess,甚至没有重定向到错误的URL。 The only thing that made any changes was using IIS for the redirects which will only redirect: http://blog.ourdomain.com/2017/03/orientation-packages-for-new-employees/ to: http://www.ourdomain.com/blog/ 唯一做出改变的是使用IIS进行重定向,只重定向: http//blog.ourdomain.com/2017/03/orientation-packages-for-new-employees/ to: http:// www。 ourdomain.com/blog/

Please help. 请帮忙。 What else should we try? 我们还应该尝试什么? What are we doing wrong? 我们做错了什么?

Thanks everyone for the advice. 感谢大家的建议。 What ended up working was using specific redirects in the web.config file. 最终工作的是在web.config文件中使用特定的重定向。 Our biggest issue here was not understanding that the htaccess file is only used by Apache. 我们这里最大的问题是不了解htaccess文件仅供Apache使用。 We have Windows server with IIS7 which uses the web.config file. 我们有带有IIS7的Windows服务器,它使用web.config文件。 Below are some examples of what we added. 以下是我们添加的一些示例。 Please understand that this worked for us because of the URL formatting used with our Wordpress installation. 请理解,这对我们有用,因为我们的Wordpress安装使用了URL格式。

 <?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite> <rules> <rule name="Redirect - Category - Paging"> <match url="^category/([_0-9a-z-] )/page/([0-9] )/" /> <action type="Redirect" url="http://www.ourdomain.com/blog/category/{R:1}/page/{R:2}" redirectType="Permanent" /> </rule> <rule name="Redirect - Category"> <match url="^category/([_0-9a-z-] )/" /> <action type="Redirect" url="http://www.ourdomain.com/blog/category/{R:1}" redirectType="Permanent" /> </rule> <rule name="Redirect - Author"> <match url="^author/([_0-9a-z-] )/" /> <action type="Redirect" url="http://www.ourdomain.com/blog/author/{R:1}" redirectType="Permanent" /> </rule> <rule name="Redirect - Individual Blog"> <match url="^([0-9] )/([0-9] )/([_0-9a-z-] )/" /> <action type="Redirect" url="http://www.ourdomain.com/blog/{R:1}/{R:2}/{R:3}" redirectType="Permanent" /> </rule> <rule name="Redirect - Month Archive"> <match url="^([0-9] )/([0-9] )/" /> <action type="Redirect" url="http://www.ourdomain.com/blog/{R:1}/{R:2}" redirectType="Permanent" /> </rule> <rule name="Redirect - About Us"> <match url="^about-us/" /> <action type="Redirect" url="http://www.ourdomain.com/blog/about-us" redirectType="Permanent" /> </rule> <rule name="Redirect - Privacy"> <match url="^privacy/" /> <action type="Redirect" url="http://www.ourdomain.com/blog/privacy" redirectType="Permanent" /> </rule> <rule name="Redirect - Home Page - Paging"> <match url="^page/([0-9] )/" /> <action type="Redirect" url="http://www.ourdomain.com/blog/page/{R:1}" redirectType="Permanent" /> </rule> <rule name="Redirect - Home Page"> <match url="^" /> <action type="Redirect" url="http://www.ourdomain.com/blog" redirectType="Permanent" /> </rule> </rules> </rewrite> <defaultDocument> <files> <add value="index.php" /> </files> </defaultDocument> </system.webServer> </configuration> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM