Forum Moderators: phranque

Message Too Old, No Replies

Redirecting non-www -> www

         

iaaa

7:55 am on Apr 19, 2006 (gmt 0)

10+ Year Member



Hi all,

I have created the .htaccess file in the root of my web folder (/var/www/html/) with the following lines:

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

Whenever I type example.com on the browser it takes me to www.example.com, so it seems to do the trick. Does it look alright in terms of carrying PR across to the www. enabled version of the domain? Am I right to have included the trailing slash (before the $1). I wasn't 100% sure about that.

Thank you in advance

[edited by: jdMorgan at 1:34 pm (utc) on April 19, 2006]
[edit reason] Formatting [/edit]

MichaelBluejay

2:06 am on Apr 20, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If it works, it works. There's nothing magical about PR.

About including the slash, again, if it works, it works. But since you want a specific answer: Yes.

smokeybarnable

5:51 am on Apr 26, 2006 (gmt 0)

10+ Year Member



I used this same code and it worked however all my secure pages disappeared?

smokeybarnable

6:30 am on Apr 26, 2006 (gmt 0)

10+ Year Member



I added this line and it seemed to solve the problem.

RewriteCond %{SERVER_PORT} !^443$

I wish I knew why it worked though..hehe

[edited by: jdMorgan at 1:50 pm (utc) on April 26, 2006]
[edit reason] Formatting [/edit]

jdMorgan

1:52 pm on Apr 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It works becuase the added RewriteCond makes the RewriteRule conditional -- The rule is only applied if the request is NOT to port 443 -- the default SSL port. So, the rule is only applied to non-SSL requests.

Jim