【问题标题】:How to rewrite old urls to new urls to preserve Google Ranking如何将旧网址重写为新网址以保留 Google 排名
【发布时间】:2013-07-04 06:21:31
【问题描述】:

我已将静态 HTML 网站重新开发为动态 PHP 网站,旧网站具有我不想失去的 Google 排名。

旧网址结构

www.mysite.com/somepage/index.html

新的网址结构:

www.mysite.com/page.php?id=10 其中10somepage 的ID

我尝试过这种方法,但没有成功。

<IfModule mod_rewrite.c>
    RewriteEngine On
    Redirect 301 /somepage/index.html www.mysite.com/page.php?id=10
</IfModule>

【问题讨论】:

    标签: .htaccess mod-rewrite url-rewriting http-status-code-301 google-ranking


    【解决方案1】:

    请注意,Redirect 不是 mod_rewrite 的一部分,它是 mod_alias 的一部分,您无需打开重写引擎即可使用它。

    如果您想“重写”,例如,在服务器内部更改 URL,而互联网的其余部分不知道它已被更改,那么您将使用 mod rewrite,而不是重定向:

    RewriteEngine On
    RewriteRule ^/?somepage/index\.html$ /page.php?id=10 [L]
    

    如果您想将所有请求重定向到新的 URL,那么您可以单独使用 Redirect。这让互联网的其余部分知道 URL 已更改并停止使用旧 URL。使用 301,谷歌知道当存在 301 重定向(永久)时,它为旧 URL 存储的任何元数据都应该迁移到新 URL:

    Redirect 301 /somepage/index.html /page.php?id=10
    

    由于您在同一主机内进行重定向,因此不需要主机名。

    【讨论】:

    • 我只想让旧网址继续工作以保持谷歌排名。 RewriteRule ^/?sompage/index\.html$ /page.php?id=10 [L] 将用于此目的,对吧?
    • 请纠正拼写错误,它的 somepage 不是 sompage。无论如何接受解决方案:)
    猜你喜欢
    • 2016-11-03
    • 2015-10-27
    • 2017-05-10
    • 1970-01-01
    • 2016-11-22
    • 1970-01-01
    • 1970-01-01
    • 2018-07-31
    • 1970-01-01
    相关资源
    最近更新 更多