Forum Moderators: phranque

Message Too Old, No Replies

Non-www to www

In second domain on primary account

         

Stefan

3:40 pm on Jun 9, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



My hosting company allows for five domains on my account, and I recently added a second. I can't seem to get the non-www to www .htaccess redirect to work for the second domain (example.info). I looked around in the WW threads and can't find anything specifically addressing it.

The index.htm and .htaccess for example.info are located in var/www/vhosts/example/ of maindomain.org.

The .htaccess code is:

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

Does anyone know if this method won't work if it's on a second domain of a primary account? If it should, I might have something else not set right. I did set up the www subdomain for example.info.

jdMorgan

10:26 pm on Jun 9, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your code should work, as far as I can see. Did you completely flush your browser cache?

Jim

Stefan

1:31 pm on Jun 10, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks, Jim.

Yeah, I cleared the cache in Firefox, and also tried it in Opera and IE, which I hadn't checked it with previously (so there shouldn't have been a cache problem). I think it must have something to do with where it is in the VPS. The code has worked fine in maindomain.org since I first used it (actually a slight variation), a few years ago. This is the first time I've added another domain, though, and it's proving to be a learning experience. It took me a few days just to get it to resolve in the browser with the right URL, rather than showing as maindomain.org/second-domain/ - I made the mistake of putting it where the help info for the hosting company said to - /var/www/html/second-domain/index.htm. Apparently, something to do with the email was causing it to not resolve properly.

Stefan

2:18 pm on Jun 11, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Success! I needed to edit the httpd.conf to turn on mod_rewrite for the new directory. She works like a charm now.

<VirtualHost *:80>
ServerName example.info
ServerAlias www.example.info
DocumentRoot /var/www/vhosts/example
<Directory "/var/www/vhosts/example">
Options FollowSymLinks MultiViews Includes ExecCGI
AddHandler cgi-script .cgi .pl .py .sh
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

(Posted in case someone else has the same problem and comes across this thread.)

jdMorgan

4:09 pm on Jun 11, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are you actually using MultiViews for content negotiation? If not turn them off!

Jim

Stefan

5:00 pm on Jun 11, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Geez, no Jim. I wasn't even sure what it was - got the code from the hosting forum. Do I just delete "Multiviews"?

Thanks, eh. It's much appreciated.

Stef

<added>I just looked at the httpd.conf and it's also there for the main domain, by default it seems. This is the first I've touched that file and I only added that code to the <VirtualHost...> part.

<added again>Just read a little on it, although I don't understand much. I don't use content management or php - just straight html. Should I yank it from the main domain as well? It's there for the main domain html folder, I believe:
<Directory "/var/www/html">
Options FollowSymLinks MultiViews Includes ExecCGI
AddHandler cgi-script .cgi .pl .py .sh
AllowOverride All
Order allow,deny
Allow from all
</Directory>

[edited by: Stefan at 5:33 pm (utc) on June 11, 2008]

Stefan

6:36 pm on Jun 11, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ok, I turned it off in the .htaccess for the maindomain html folder:

Options +FollowSymLinks -MultiViews
etc...

I just backspaced out ¦MultiView¦ in the <VirtualHost> part of the httpd.conf

Thanks for warning me, man. I know not what I do ;-)

S