[Resolved] Redirect non-WWW to WWW using httpd.conf

Status
Not open for further replies.
#1
I've seen lots of various examples, and lots of varying opinions on the correct methods to use, most of them for .htaccess with the implication that they will work with httpd.conf , Figured I'd ask the experts here since I'm using lightspeed as my web server.

Desired result: one piece of code that will redirect all the domain names on my server from non www to www

Here are a couple of the most popular solutions I came across.

Method 1:
Code:
<VirtualHost *:80>
    ServerName example.com
    Redirect permanent / http://www.example.com/
</VirtualHost>
Would this method work with some wildcards for all domains instead of just one? If so, what would the exact code be?


Method 2:
Code:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
This seems to do what I think I want, but a few posters said it was "to Heavy handed" of an approach. Not sure what that meant exactly.


Method 3:
Code:
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ %{REQUEST_SCHEME}://www.%{HTTP_HOST}$1 [R=301,L]
I'm looking for the cleanest solution that works well on lightspeed?

Thanks,
Jason
 
Last edited by a moderator:

NiteWave

Administrator
#2
there should be no difference between apache and litespeed regarding this topic.

I think method 2 or 3 are fine.
I don't think "too heavy handed"(?) -- this rewrite rule is light weight.
 
Status
Not open for further replies.
Top