【问题标题】:how to redirect users from old urls to new urls in SEO friendly manner如何以 SEO 友好的方式将用户从旧网址重定向到新网址
【发布时间】:2013-07-25 05:54:07
【问题描述】:

不要认为这是一个重复的问题。是的,这有点重复,但需要澄清一些关于我的网站的问题。

我已将旧网址更改为带有更多参数的新网址。喜欢,

旧网址1:-http://www.example.com/Threads/24/sample-thread.html

新 URL1:- http://threads.example.com/IN/24/215/sample-thread.html // (IN,215 can be changed. 24 remains)

旧网址1:-http://www.example.com/Threads/25/sample-thread2.html

新 URL2:- http://threads.example.com/UK/25/302/sample-thread2.html // (UK,302 can be changed. 25 remains)

Both pages are having same contents and both URLs refers to the same page。由于 Google 中有很多索引页面,我不想失去访问者。

所以我想将旧网址重定向到新网址而不影响搜索引擎。我的情况最好的解决方案是什么?

.htaccess 还是 php?我应该和什么一起去?

谢谢

【问题讨论】:

    标签: php .htaccess redirect


    【解决方案1】:

    你应该用php去

    只需在旧网址中添加以下代码,它会将您重定向到新网址

    新网址1

    <?php
        header("Location: http://threads.example.com/IN/24/215/sample-thread.html");
    ?>
    

    对所有页面执行此操作

    【讨论】:

    • 谢谢朋友。如果我像这样重定向它,它会像 301 重定向一样工作吗?
    • 是的,这是将 URL 重定向到新页面的好方法,它的 SEO 友好重定向方法。
    • 好的。既然两个链接都指向同一个页面,我认为它会导致无限重定向?我说的对吗?
    • 两个链接??您只需在页面顶部的旧页面中添加此代码
    • 对不起,我忘记了。我决定从网站上删除所有旧页面。我想如果我使用这种方法,那么在新 URL 被编入索引之前我无法删除旧页面。
    【解决方案2】:

    带有R=301(永久重定向)的mod_rewrite 是处理这种情况的标准方法(将旧的URL 移动到新的)。

    通过httpd.conf启用mod_rewrite和.htaccess,然后把这段代码放到你.htaccessDOCUMENT_ROOT目录下:

    Options +FollowSymLinks -MultiViews
    # Turn mod_rewrite on
    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{HTTP_HOST} ^(www\.)?example.com$ [NC]
    RewriteRule ^Threads/(24)/([^.]+\.html)$ http://threads.example.com/IN/$1/215/$2 [L,R=301,NC]
    
    RewriteCond %{HTTP_HOST} ^(www\.)?example.com$ [NC]
    RewriteRule ^Threads/(25)/([^.]+\.html)$ http://threads.example.com/UK/$1/302/$2 [L,R=301,NC]
    

    【讨论】:

    • 谢谢朋友。如果 URL 是动态的并且 IN,​​215 是从数据库中获取的会怎样?
    • .htaccess 无法查询数据库,但如果只有一堆这些值,您可以将它们存储在平面文件中并利用 RewriteMap 功能。
    猜你喜欢
    • 1970-01-01
    • 2013-01-06
    • 2010-12-11
    • 1970-01-01
    • 1970-01-01
    • 2021-10-21
    • 2021-06-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多