I want 301 redirect from example.com to www.example.com. This really is working solution, however when I paste it entirely .htaccess site go lower.

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

Relaxation .htaccess file

php_flag magic_quotes_gpc off
php_flag magic_quotes_runtime off
php_flag register_globals off

RewriteEngine On

RewriteRule ^.htaccess$ - [F]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*)$ $1 [L]
Options -Indexes
AddDefaultCharset windows-1251
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(service|news|search|project)/?$ index.php?menu=$1
RewriteRule ^error/([0-9]+)/?$ index.php?menu=error&loadinfo=$1
RewriteRule ^page/([0-9]+)/?$ index.php?menu=page&loadinfo=$1
RewriteRule ^news/([0-9]+)/?$ index.php?menu=news&loadinfo=$1
RewriteRule ^news/page-([0-9]+)/?$ index.php?menu=news&page=$1
RewriteRule ^service/([0-9]+)/?$ index.php?menu=service&category=$1
RewriteRule ^service/([0-9]+)/([0-9]+)/?$ index.php?menu=service&category=$1&loadinfo=$2
RewriteRule ^project/([0-9]+)/?$ index.php?menu=project&loadinfo=$1

I have tried it!

Just append this code

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

What is the AllowOverride worth of the folder in which you have your .htaccess? Your DocumentRoot (or VirtualHost) specs must be set to a minimum of AllowOverride Options to be able to allow php_flag within .htaccess files.