htaccess重定向与php重定向 [英] htaccess redirect vs php redirect

查看:118
本文介绍了htaccess重定向与php重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我决定将我所有的/dyanmic.php?UID=...页面更改为/static/Name-From-DB. 我已经读过,进行SEO重定向的最佳方法是实现301 .htacess重定向:

I have decided to change all my /dyanmic.php?UID=... pages to /static/Name-From-DB. I have read that the best way to do redirection, SEO wise, is to implement a 301 .htacess redirection:

(http://www.tamingthebeast.net)-正确的方法-htaccess 301 重定向:301重定向最多 高效且对蜘蛛/访客友好 网站的策略 托管在运行Apache的服务器上.

(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文件中具有成千上万的条目似乎效率很低:

However, since I have thousands of pages I need to use redirection for, it seems pretty inefficient to have thousands of entries in the .htacess file:

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将标头设置为301重定向:

Therefore it seems like the efficient way to do it is via the PHP page, setting the header to 301 redirection according to the UID:

<?
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,这种方法是否会对网页的排名产生负面影响.

My question is if this method will effect in a negative way on my pages' rankings, considering the paragraph I quoted above that the best way to do a redirection is through the .htaccess.

谢谢!

推荐答案

无论采用哪种方式,相同的标头都将以相同的方式发送.因此,对用户(或搜索引擎)而言,这没有什么不同,因此与.htaccess相比,PHP不会对您的网页排名产生负面影响.

The same headers will be sent the same whichever way you do it. Therefore, to the user (or to a search engine) it won't be any different so the PHP won't negatively effect your page rank compared to the .htaccess way.

由于每次访问该页面时,都会触发数据库查询,因此PHP的方式会稍慢一些.如果该网站访问这些页面的流量不多,那应该不是问题.

The PHP way will be a little bit slower as every time the page is accessed a database query is fired off. If the site doesn't have too much traffic going to those pages it shouldn't be an issue though.

在您的PHP页面中,首先进行数据库连接,因为如果该页面不存在,您将需要将它们重定向到另一个页面或传递404错误标头而不是301标头.

In your PHP page, do the database connection first because if the page doesn't exist you will want to either redirect them to another page or pass 404 error headers instead of the 301 header.

这篇关于htaccess重定向与php重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆