post Category: Code — Chris @ 10:42 pm — post Comments (2)

Here’s a rather wonderful mod_rewrite script that makes your website very google friendly. It will take any Request_URI and concatenate www. to its start. Search engines such as google love this consistency. This is why some of my articles feature on page 1 of google’s search results, often very quickly after being published.

Here’s the script which you should put in either your vhost configuration file or docroot .htaccess file

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Thanks to RichardK, resident mod_rewrite consultant at the mod_rewrite forums.

Horaayy..there are 2 comment(s) for me so far ;)

#1

Thanks for this. Can’t seem to get it working though. Is there any specific setting you could point this down to and in what file (this is for an apache server)?

Adaptiv Media wrote on April 26, 2008 - 6:30 pm
#2

Hi,

As the article notes, you should put this in your .htaccess file or within your vhost httpd configuration. I, personally, put these in my vhost configuration (well, i tell a lie – this site uses Zeus ZXTM for URL re-writes across my Apache cluster) as requiring httpd to read *every* document directory for every request is hugely inefficient. My advice is to put this within your vhost file. Please contact your OS vendor for assistance with this if you require httpd help.

All the best,
Chris

chris wrote on April 27, 2008 - 1:13 am
You can leave a response, or trackback from your own site.

Write Your Comment

Comment Guidelines: Basic XHTML is allowed (a href, strong, em, code). All line breaks and paragraphs will be generated automatically.

You should have a name, right? 
Your email address, I promised I won't tell it to anyone. 
If you have a web site or blog, you can type the URL right here. 
This is where you type your comments. 
Remember my information for the next time I visit.
 

This is a captcha-picture. It is used to prevent mass-access by robots. (see: www.captcha.net)

You must read and type the 4 chars within 0..9 and A..F, and submit the form.

  

Oh no, I cannot read this. Please, generate a