【问题标题】:301 redirect from one domain to another but only for specific pages301 从一个域重定向到另一个域,但仅针对特定页面
【发布时间】:2019-03-15 06:18:06
【问题描述】:

我们正在为客户重建一个从 ASP 到 WordPress 的网站。该网站将具有不同的域、url 结构和文件扩展名。我只是对 htaccess 301 重定向有所了解,而且我知道我不能执行以下操作:

Redirect 301 http://www.site1.com/about_us.asp https://site2.com/about/
Redirect 301 http://www.site1.com/art-specs/ https://site2.com/specs/
Redirect 301 http://www.site1.com/page/product1/ https://site2.com/product1/

总共有大约 12 个链接需要重定向,我想确保它在第一时间就正确完成,因为客户的 SEO 排名在线。

我可以使用上述格式的变体吗?还是需要先完成的重写规则?任何帮助(和解释)将不胜感激!

【问题讨论】:

标签: .htaccess redirect


【解决方案1】:

在深入研究之后,我意识到 htaccess 文件除了对原始域的相对访问之外不需要任何其他内容。

即您不需要声明:http://www.site1.com/about_us.asp,因为服务器和域的配置方式应使/about_us.asp 具有相同的含义。

所以正确的答案是:

[1] 通过将原始域添加为插件域(例如 http://www.site1.com/)来配置服务器(在我的情况下为 cPanel)。

[2] 在 htaccess 文件中,我会将每个 301 重定向添加到 htaccess 文件中:

Redirect 301 /about_us.asp https://site2.com/about/
Redirect 301 /art-specs/ https://site2.com/specs/
Redirect 301 /page/product1/ https://site2.com/product1/

...for each redirect

[3] 最后,将以下内容添加到 htaccess 文件的底部将捕获其他所有内容并将它们重定向到主页:

RedirectMatch 301 .* https://site2.com

【讨论】:

    猜你喜欢
    • 2013-05-18
    • 2017-06-15
    • 2011-03-04
    • 1970-01-01
    • 2011-12-21
    • 2011-04-26
    • 2019-12-12
    • 2013-02-24
    • 1970-01-01
    相关资源
    最近更新 更多