301使用新网址重定向Wordpress

时间:2017-03-22 16:16:17

标签: wordpress .htaccess redirect

我们使用Wordpress Move插件将我们的Wordpress网站从blog.ourdomain.com迁移到www.ourdomain.com/blog,我们无法让301重定向工作。这是我们的全部过程......

  1. 制作wordpress网站文件夹的副本为' blog.ourdomain.com - 复制'
  2. 使用Wordpress Move插件将URL从blog.ourdomain.com更改为www.ourdomain.com/blog。
  3. 使用IIS,创建了博客'作为ourdomain.com下的虚拟目录,它指向现有的blog.ourdomain.com'文件夹中。
  4. ......此时,新网站工作正常......

    1. 使用IIS,将blog.ourdomain.com的请求指向' blog.ourdomain.com - 复制'这样我们就可以使用htaccess和web.config文件夹,而不会影响实时网站。
    2. 我们在htaccess文件中尝试了几种不同的301组合,但似乎没有任何效果。我们还尝试使用IIS进行重定向,这确实有效,但我们无法使用动态URL并重定向到正确的页面。
    3. 以下是我们需要的示例:

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

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

      也许子目录是弄乱我们的部分,但我们根本没有使用htaccess取得任何成功,甚至没有重定向到错误的URL。进行任何更改的唯一方法是使用IIS进行重定向,该重定向仅重定向: http://blog.ourdomain.com/2017/03/orientation-packages-for-new-employees/ 至: http://www.ourdomain.com/blog/

      请帮忙。我们还应该尝试什么?我们做错了什么?

1 个答案:

答案 0 :(得分:0)

感谢大家的建议。最终工作的是在web.config文件中使用特定的重定向。我们这里最大的问题是不了解htaccess文件仅供Apache使用。我们有带有IIS7的Windows服务器,它使用web.config文件。以下是我们添加的一些示例。请理解这对我们有用,因为我们的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>
&#13;
&#13;
&#13;

相关问题