PDA

View Full Version : .htaccess file - forcing www.



webing
05-16-2008, 03:20 PM
Hi, i'm trying to force www.example.com using the .htaccess file but i'm not sure i've done it correctly:

i'm using this code:

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



well i created the .htaccess file and it's a html file, i put the code at the top so:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^.example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
<html>
<head>
so on so on

when i refresh my website i get this:

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, webmaster@hidden.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.


--------------------------------------------------------------------------------

Apache/2.2.8 (Unix) mod_ssl/2.2.8 OpenSSL/0.9.8g DAV/2 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 Server at hidden.com Port 80

Any solutions please?

sorry for asking so many questions :(.

r2b2
05-16-2008, 04:12 PM
.htaccess files aren't HTML files - they're seperate.

You have one .htaccess file per directory. So if you create a file called .htaccess in the directory where your HTML files reside and put the Rewrite* parts of example there.

Then create another yourfile.html file to contain the HTML bit. (i.e. remove the HTML bits from the .htaccess file and you should hopefully be fine)

marcrosoft
05-16-2008, 08:16 PM
I wrote an article on my blog on this topic see, Duplicate Content www vs. non-www Canonical Problems (http://www.marksanborn.net/seo/duplicate-content-www-vs-non-www-canonical-problems/).

r2b2 is correct.

.htaccess files are basically configuration files for your individual domain. They are very common on shared hosting webhosts.

You will need to follow the instructions on my post. The .htaccess fill will then need to be uploaded into the root directory. ie. http://www.yourdomian.com .

Btw, you are on the right track by forcing the www. It is the standard and you will not be penalized by search engines by having duplicate content.

webing
05-17-2008, 01:21 AM
too late i'm already doubled content :P, google indexes you fast when you don't want it and slow when you want it!

thanks for both answers but i'm still confused, will go to the link marcrosoft gave and see what i can do. Thanks.

webing
05-17-2008, 01:34 AM
ok i looked at the link, i guess my code was abit wrong :P, now theres no error but it seems to only work when i refresh the page, is that how it's supposed to happen?

What i mean is, if i go to example.com it stays http://example.com but if i refresh the page it goes to www.example.com --- shouldn't it automaticly redirect me or have i done something wrong?

marcrosoft
05-17-2008, 05:04 PM
It should definitely be automatic.

This is odd...

webing
05-18-2008, 02:34 AM
i guess it just toke it's time to adjust or something, works fine now, thanks all for the help!

marcrosoft
05-19-2008, 11:51 AM
You're welcome, I am glad everything worked out :)