0

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

我已将旧 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?我应该和什么一起去?

谢谢

4

2 回答 2

2

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

通过启用 mod_rewrite 和 .htaccess httpd.conf,然后将此代码放在您.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]
于 2013-07-25T06:26:24.430 回答
2

你应该去 php

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

新网址1

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

对所有页面执行此操作

于 2013-07-25T05:58:45.420 回答