02 Apr
Posted by ProCOM
on April 2, 2008 – 1:25 am - 538 views
If you're new here, you may want to subscribe to my RSS feed. So that you can read the latest updates about Web2.0 tools, Making Money Online, Tips in SEO, Ajax and many more. Thanks for visiting ProgramimiCOM!
One of the first things I do when I begin implementing a site is to force the www (or no-www) in the domain name. Why would I want to do this? For search engine optimization of course. For example, programimi.com redirects to www.programimi.com. What this means for Google is that it gets crawled as one site. Sites that link to programimi.com will add to the pagerank of www.programimi.com. Theoretically, this could double your Pagerank score (but not necessarily your Pagerank rating).
Anyway, here is the code to add to your .htaccess file to force www, but make sure mod_rewrite apache module is turned on:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(.*)\.programimi\.com$ [NC]
RewriteRule ^(.*)$ http://www.programimi.com/$1 [R=301,L]
And here is the code to force no-www (in spirit of no-www.org):
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.programimi\.com$ [NC]
RewriteRule ^(.*)$ http://programimi.com/$1 [R=301,L]
Of course, replace programimi.com above with your own domain name. To edit your .htaccess file you may need to enable view hidden files, or if the file doesn’t exist, you’ll have to create it yourself. The best way is to do it through an SSH connection to your server.
If you don’t have access to .htaccess, you could also accomplish the same thing through php with a simple script at the top of every page that will try to find www in the URL and redirect if found. Not the most elegant solution, but it does what it needs to do for those who can’t edit .htaccess for some reason.
if(!substr($_SERVER[’HTTP_HOST’], ‘www’)) //check if www exists in URL
{ header(’Location: http://www.programimi.com/’); //redirect to www.programimi.com
}
Or for those using wordpress, you could simply install a plugin that does all this for you! One example plugin is WWW-Redirect.
Print This Post
Email This Post
One Response
How To Create Various Redirects | ProgramimiCOM
April 7th, 2008 at 12:33 am
1[…] Redirect Using .htaccess to redirect has several purposes. Similar to forcing www, you can use mod_rewrite to send users to a different destination. The code is simple — redirect […]
Comments RSS
TrackBack Identifier URI
You must be logged in to post a comment.