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

时间:2013-07-25 05:54:07

标签: php .htaccess redirect

不要认为这是前面提到的重复问题。是的,这有点重复,但需要澄清一些关于我网站的内容。

我已将旧网址更改为包含更多参数的新网址。像,

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

新网址1: - 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

新网址2: - 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中有很多索引页面,我不想放弃访问者。

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

.htaccessphp?我该怎么办?

谢谢

2 个答案:

答案 0 :(得分:2)

你应该使用php

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

新网址

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

为所有页面执行此操作

答案 1 :(得分:2)

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

通过httpd.conf启用mod_rewrite和.htaccess,然后将此代码放在.htaccess目录下的DOCUMENT_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]
相关问题