我已决定将我所有的 /dyanmic.php?UID=...
页面更改为 /static/Name-From-DB
。
我读过,在 SEO 方面,进行重定向的最佳方法是实现 301 .htacess 重定向:
(http://www.tamingthebeast.net)- The right way - a htaccess 301 Redirect: A 301 redirect is the most efficient and spider/visitor friendly strategy around for web sites that are hosted on servers running Apache.
但是,由于我有数千个页面需要使用重定向,因此在 .htacess 文件中包含数千个条目似乎效率很低:
redirect 301 /dynamid.php?UID=1 http://www.domain.com/static/Name-From-DB
redirect 301 /dynamid.php?UID=2 http://www.domain.com/static/Another-Name-From-DB
and so on...
因此,似乎最有效的方法是通过 PHP 页面,根据 UID 将 header 设置为 301 重定向:
<?
Header( "HTTP/1.1 301 Moved Permanently" );
// Getting the page static name from the DB according to the UID
$result = mysql_query('SELECT Name FROM DB WHERE UID='$_GET["uid"]'');
$row=mysql_fetch_assoc($result);
// Redirect to the new page
Header( "Location: http://www.domain.com/static/" . $row[0] );
?>
我的问题是这种方法是否会对我的网页排名产生负面影响,考虑到我在上面引用的段落,进行重定向的最佳方式是通过 .htaccess。
谢谢!
最佳答案
无论您采用何种方式,相同的 header 都将以相同的方式发送。因此,对于用户(或搜索引擎)而言,它不会有任何不同,因此与 .htaccess 方式相比,PHP 不会对您的网页排名产生负面影响。
PHP 方式会稍微慢一些,因为每次访问页面时都会触发数据库查询。不过,如果网站没有太多访问这些页面的流量,那应该不是问题。
在您的 PHP 页面中,首先进行数据库连接,因为如果该页面不存在,您将需要将它们重定向到另一个页面或传递 404 错误 header 而不是 301 header 。
关于php - htaccess 重定向 vs php 重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4094932/