0

I have hundreds of domains so I needed an htaccess that would force www without knowing the exact domain name.

I got it to work, but then it started forcing www in front of ALL my subdomain URLs too, not just domain.com (ex: http://www.sub.domain.com). So I need something that will force www only if the user inputs domain.com.

I tried tweaking my original code and it's not working. Any suggestions?

RewriteCond %{HTTP_HOST} ^%{HTTP_HOST}$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST} [R=301,L]

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by rch1231
0

I am just curious why you don't simply use a ServerAlias entry in the hpptd.conf file like most sites:

<VirtualHost *:80>
        ServerAdmin webmaster@txlinux.com
        DocumentRoot /var/www/html/txlinux.com
        ServerName txlinux.com
        ServerAlias www.txlinux.com
        ErrorLog logs/txlinux.com-error_log
        CustomLog logs/txlinux.com-access_log common
</VirtualHost>
0

Then you are going to have to request the addition of the ServerAlias entry from your provider. To use the htaccess file they have to first get to your web site and if www.domain.com is not redirecting there then they would never get to the point where they would access the file. Does that make sense?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.