Cổng vào tri thức => Tin học => Topic started by: saos@ngmo on 30/03/07, 12:19 Return to Full Version

Title: Tất cả về URL redirect
Post by: saos@ngmo on 30/03/07, 12:19
URL Redirect

URL Redirect Logo URL Redirect resource! How to do a meta refresh redirect, php redirect, asp redirect, coldfusion redirect, javascript redirect, shtml redirect and 301 redirect! All on one page with the code on how to do it and examples!
Valid XHTML! Valid CSS!

URL Redirect can be needed for a number of reasons! You may want to rediect your example.com to www.example.com or the other way around so that search engines don't see them as two different sites. You may have an old file that has SERP but you have changed your directory structure and you want to leave that file in place but point it to the new file.

Perhaps you have purchased an example.com, example.net and example.org and you want to forward them all to example.com . There can be lots of reasons to do URL redirects.

To check your redirect to make sure it is working correctly use this Check Server Header Tool.
301 URL Redirect

A 301 URL redirect for seocompany.ca (test it) is used to redirect seocompany.ca to www.seocompany.ca . The search engines see both of these URLs as different web sites so you should point one to the other.

If you have inbound links pointing to both the www and non-www you may get ranking weight and Pagerank vote to both your non-www and your www sub-domains. This would divide your ranking weight and Pagerank between two files.

I also included a sample of a 301 file redirect in the code www.seocompany.ca/htaccess-url-redirect.html.

*Note: Back in June of 2004 there was to be a problem with Yahoo if you did a 301 redirect. Check out the following links. Yahoo's 301 Redirect Penalty, Yahoo 301 Redirect indexing problem and Fixing yahoo 301 bug. Yahoo! Help claims there is no problem with this now.

June 12th: Now there are claims that if you don't do a 301 redirect you can pick up a duplication penalty with Google? lots0 discusses this on a post over at threadwatch.org called Using Canonical Domains to Sabotage Competitors in Google, and Dan Thies blogs a post called example.com vs. www.example.com... trouble! discussing the same issue.

The code to redirect seocompany.ca to www.seocompany.ca would be as follows.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.seocompany\.ca [NC]
RewriteRule ^(.*)$ http://www.seocompany.ca/$1 [L,R=301]
</IfModule>

The code to redirect www.seocompany.ca to seocompany.ca would be as follows.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^seocompany\.ca [NC]
RewriteRule ^(.*)$ http://seocompany.ca/$1 [L,R=301]
</IfModule>
301 URL Redirect For Moving Domains.

Add the following code into the .htaccess in the old site where you want to forward all files and directories to have a permenant redirect to the same files and directories in the new site. You will need to set up the new site with all the same directories and files as the old site for this redirect to work correctly. In the below example the www.seocompany.ca site is the new site.

I would strongly suggest that you contact the sites that were linked to the old domain and ask them to change the links to point to your new domain. Currenty Google is passing all the ranking weight and Pagerank vote but at some point they may start devaluing the ranking weight and Pagerank vote that is passed.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^/(.*)$ http://www.seocompany.ca/$1 [R=301,L]
</IfModule>

If you want to redirect sub-domains also you can add the following to the .htaccess on the root of your olddomain.com .

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} (.*)\olddomain\.com
RewriteRule ^(.*) http://%1seocompany.ca/$1 [R=301,L]
</IfModule>

Check out How To Redirect Browser Requests in Internet Information Services 5.0 if you have Admin access to the MicroSoft IIS Server your are hosting your site on.
Meta Refresh URL Redirect

Meta Refresh URL Redirect is an example of a meta refresh URL redirect. The code is quite simple.
<meta http-equiv="refresh" content="8;url=http://www.seocompany.ca/index.html" />
Meta tag refresh is known to not be very search engine friendly and is consider spammy because of its misuse. If you keep it up around 8 seconds it is said it is ok. This method displays the new page that the refresh points to.
PHP URL Redirect

PHP URL Redirect is just like it says. The code for this script is short and simple. The following code goes at the top of the page.
<?php
header("location:http://www.seocompany.ca/index.html");
exit;
?>
This script shows the new page that the refresh points to.
301 ASP URL Redirect
RewriteRule ^(.*)$ http://www.seocompany.ca/$1 [R=301,L]

ASP URL Redirect does the redirect quite quickly. The code goes at the top of the page.
<%@ Language=VBScript %>
<%
Response.Status="301 Moved Permanently"
Response.AddHeader "Location", "http://www.seocompany.ca/index.html"
%>
This code also takes you to the redirected page.
Coldfusion URL Redirect

Coldfusion URL Redirect is about as short as they get.
<cflocation url="http://www.seocompany.ca">
This code also takes you to the redirected page.
Javascrip URL Redirect

Javascript URL Redirect shows this script in action. Again this solution only takes one line of code.
<script type="text/javascript">document.location.href='www.seocompany.ca/index.html'</script>
This code also sends you to the redirected url.
shtml URL Redirect

shtml URL Redirect displays the same code but don't redirect you to the page like the other processes.
<!--#include virtual="http://www.seocompany.ca/index.html"-->

tham khảo tại http://www.seocompany.ca/seo/url-redirect.html