如何以SEO友好的方式将用户从旧URL重定向到新URL


how to redirect users from old urls to new urls in SEO friendly manner

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

我已经将我的旧URL更改为带有更多参数的新URL。比如

旧URL1:-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)

旧URL1:-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。由于谷歌有很多索引页面,我不想失去我的访问者。

因此,我希望在不影响搜索引擎的情况下,将旧URL重定向到新URL。对我来说,什么是最好的解决方案?

.htaccess还是php?我应该用什么?

感谢

您应该使用php

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

新URL1

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

对的所有页面执行此操作

mod_rewrite with R=301(永久重定向)是处理这种情况的标准方法(将旧URL移动到新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]