Appending www to url

RewriteEngine on

RewriteCond %{HTTP_HOST} ^$ [NC]

RewriteRule ^(.*)$$1 [R=301,L]

the above code works for but only is giving "page not found"

I simply want www appended automatically. Please help.

7 Replies

Try this:

RewriteCond %{HTTP_HOST} !^$

RewriteRule ^(.*)$$1 [R=301]

It seems the problem still persists, my browser cache has been fooling me.

It turned out to be more of a redirection problem than rewrite rules so here is the solution.

In linode dns

In Virtual host



In the website directory .htaccess file is supposed to contain;

RewriteEngine on

RewriteCond %{HTTP_HOST} ^$ [NC]

RewriteRule ^(.*)$$1 [R=301,L]

Is the goal to make == ?

If so then you don't need a redirect rule just make sure your DNS is setup right.

The goal, most likely, is to have exactly one of '' or '' be the canonical hostname for the site by redirecting the "wrong" one to the "correct" one. This is generally considered a good thing to do, both for aesthetics and for making things easier on web crawlers. (It's real SEO, in other words.)


yes the idea is to have a website which is accessible by to be reached via @hoopycat is right. we want to achieve it for better seo. (currently the link is working fine)

& (currently the link gives page cannot be displayed)

to reach

Can't make it more clearer than this :(

Check if you can you ping both www and just the domain name and get back a response. Check if nslookup or dig see both names.


Please enter an answer

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct