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



我决定将我所有的/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:

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

( 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.


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
redirect 301 /dynamid.php?UID=2
and so on...


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"]'');
// Redirect to the new page
Header( "Location:" . $row[0] ); 


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.




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.


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.


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.


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