How to Redirect URLs > Invisionize.eu - IP.Board (IPB) News
Kanał Rss Kanał Rss
Kanał Atom Kanał Atom

How to Redirect URLs

wersja drukowalna wersja Microsoft Word wersja HTML

Most websites stick to one form of their domain name when they refer to their own site, be it the plain domain name, like example.com, or the www form, like www.example.com. Unfortunately others linking to you don't always follow your preferred style. If some sites link to you with just the domain name, and others link using the www subdomain, then your site may face issues with the search engines. This article shows you how you can work around the problem by automatically redirecting all URL requests of one form to the other in a search engine friendly way.

Having your site referred to as both example.com and www.example.com is not a problem of consistency. Neither is it an issue that affects branding, since most humans looking at those two hostnames will automatically assume they are referring to the same thing. In fact, most humans, when told to go to a domain like "thesitewizard.com" will automatically type "www.thesitewizard.com" in their browsers, since this is the way the majority of the websites on the Internet work, and they know it. So the problem isn't really with human beings at all.

The way to deal with it is to redirect all pages using one form of the web address ("URL") to the other form, using what is known as a "301" (or "permanent") redirection code. When the search engines see the redirection along with the 301 code, it will realise that that particular page has been permanently relocated to another address. (Don't worry if you don't understand this paragraph. It's just an overview of what you'll be doing later in this article.)

To redirect (say) example.com to www.example.com, add the following code to your .htaccess file.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

The above code causes the server to check that the hostname in the URL is example.com. If it is, the visitor will be sent to www.example.com instead.

If you also own, say example.co.uk, example.de and/or some other domain, and want them to be redirected to www.example.com as well, you may prefer to use the following code instead:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
This second set of rules checks to see if the URL has a hostname of www.example.com. If it doesn't, the visitor is redirected to www.example.com. In other words, any web address with a hostname other than www.example.com will cause a redirection to take place.

wto, 18 maj 2010

Komentarze:

Brak komentarzy

Imię/Nick:

Adres email:

Strona WWW:

Treść Komentarza: