Htaccess and www or no www

software development


I’m working with this website “stored” at some podunk webhost/ISP/thing and they way they have things set up, if you leave off the www. you get a error page from the host telling you to use Can I use an htaccess file to set it so it will force both to work? I know there’s wiki articles on forcing either or, but I want a happy medium where both work.

I know it’s a linux server, seems to be Readhat 7, and kernel 2.2.16-22.

I think I’ll also add in some custom error pages, I can just tack those lines in after the above, yes?




There’s a way to do this through the control panel:

Click on ‘Edit’ for your domain and insure that ‘Both’ is checked. That’s it.


Thanks, but as I said, it’s hosted at some podunk place that doesn’t have a clue about webhosting, so I can’t use the panel.



This will redirect the non-www to www

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^$ [NC]
RewriteRule ^(.*)$$1 [R=301,L]

It’s actually better to force it to one or the other, to avoid duplicate content penalties with people like Google. It’s also better if you care about PR, since some engines will see it as two different sites. The 301 tells them it’s permanent, so they’ll eventually update indexing, and PR would just flow to one.

It’s a friendly redirect, keep in mind, rather than Javascript or a meta-refresh. And it won’t affect a requested file, either. Ex: will become – not just redirect all requests to an index page. The user can still type it either way they want and probably won’t notice that the www gets added.

:stuck_out_tongue: Save $96 at Dreamhost with the 96DOLLARSOFF promo code.


Missed this in my first reply. Just create the pages and name them what you want, then add them to .htaccess like this:

ErrorDocument 404

:stuck_out_tongue: Save $96 at Dreamhost with the 96DOLLARSOFF promo code.


Thanks for that. I’m guessing the “host” in question has done something to disallow this. I put in the lines, like this:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^$ [NC]
RewriteRule ^(.*)$$1 [R=301,L]

That didn’t effect the and give a 500 error when going to So I tried the code inthe wiki for requiring the www and got the same results. removing the .htaccess clears up the 500 error.

Guess I’ll see if the error page stuff works or not next.



I just checked it out… that’s sneaky! I see they do it to their own domain, too. Redirecting is one thing, but they’re basically yelling at people for leaving off the www. :^D

I’m not sure if it would have any effect, but what if you remove the RewriteBase / line?

If you don’t find a work-around, you might try asking them to make both work. Not quite as convenient as the DH way of changing it, but it could be worth a try.

If it’s a no-go, and moving it isn’t an option, I’d just stress the importance of the www, whether it’s incoming links, or word-of-mouth… and hope for the best.

:stuck_out_tongue: Save $96 at Dreamhost with the 96DOLLARSOFF promo code.


If you get a 500 error from your .htaccess, then there’s an error within it. Maybe Rewrite isn’t enabled on that apache server? Maybe it’s too low version?

Either cause, 500 error from a .htaccess file means “typo”. aka, Apache didn’t understand something in it.

On that note, too, I would also vote to redirect to ‘www’ version. Reason being is ‘www’ stands for “world wide web server”, just like ‘’ means "ftp server, “” is “smtp server” and so for. It’s a naming convention thing, nothing more really. I, personally, just like to keep with a standard convenston.


removing the rewritebase line didn’t make any difference. It’s nice to know that their version of apache is only 5 years old -they’re running Apache/1.3.19. I wonder, is there even php support for this version? That could explain why it dosn’t parse php pages.

I’m doing this site as a favor for a church. It’s disspointing to me, but there’s no way they’ll put any money into it. they’re getting this deal with a local company - hosting is free. from their site, you can see the ‘server status’ which looks like they host my site, their own, and one other. I suppose you get what you pay for. It’s free and they’re getting “site storage” an E-mail address, and nothing else. no databases, no php, nada.

The other strange thing they do is only allow FTP access to their server from local IPs. They’re in a rural part of Wyoming and if I want FTP access from here in Chicago I have to call them up and ask them to allow my IP access. Then if my DSL modem resets, I loose power, or whatever I have to call them up again with my new IP. What a pain in the arse.

I’ll see about asking them to get their system to accecpt non-www, but i’m figuring they’ll say no. I’m tempted to bring them into my hosting account as a freebe, the site is so small… Oh well :frowning:

Thanks for all your help.



If there’s not even PHP support, I wouldn’t count on being able to do much there.

I’m surprised they allow HTML, instead of just making you upload .txt files. :smiley:

If you don’t mind doing that, and don’t see it becoming a burden in the future, that would be by far the easiest way to go. Even if they did add the www, I wouldn’t be surprised to run into other problems later.

Figure out what your time is worth, too. At DH, where you already know how everything works, you’d probably already be done–so moving them here could pay for itself in time saved.

If they didn’t mind a banner, even the average geocities-like free hosts would probably be a better solution than the current host.

:stuck_out_tongue: Save $96 at Dreamhost with the 96DOLLARSOFF promo code.


After hearing this horror story I’m on the verge of giving them free hosting!