Trying to force "www", having problem with subdire

Using a single web hosting account to host multiple sites

Trying to force "www", having problem with subdire

Postby aciurczak » Sat Jan 10, 2009 12:42 am

Hi all -

I'm having a surprising amount of trouble trying to add www. using mod_rewrite. I've tried using a variety of suggestions from my online searches, including the one in the FAQ here. Here's the suggested code:

Code: Select all
RewriteCond %{HTTP_HOST} ^(domain\.com)$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]


The code works fine to force domain.com to www.domain.com. But if i try domain.com/forums , it remains domain.com/forums and does not change to www.domain.com/forums.

Am I missing something obvious? I would like the entire site, from the root URL to all subdirectories, to be forced to have a www in front of them. Thanks for any advice.
aciurczak
 
Posts: 3
Joined: Sat Jan 10, 2009 12:34 am

Postby richardk » Sat Jan 10, 2009 3:15 pm

The RewriteRule (in .htaccess files and <Directory>s) matches a relative path.

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(example\.com)$ [NC]
RewriteRule .* http://www.%1%{REQUEST_URI} [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby aciurczak » Sat Jan 10, 2009 7:21 pm

Thx! I'll give this a try. I found out that the original code was actually working for every subdirectory except for the one I was testing it with, because I already had another htaccess file within the /forums directory. Hours of tweaking, for a 10-second "doh!". But I'm still stuck a bit, because I need that other .htaccess file for a different reason. Here's my current htaccess file in the root folder:

Code: Select all
Options +FollowSymLinks

RewriteEngine On

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


And it works fine for all but the forums directory. I have this htaccess file in the /forums directory:

Code: Select all
RewriteEngine On
RewriteRule ^((urllist|sitemap).*\.(xml|txt)(\.gz)?)$ vbseo_sitemap/vbseo_getsitemap.php?sitemap=$1 [L]


What that does is rewrite bots coming in at http://www.domain.com/sitemap.gz to the php code that dynamically generates a sitemap.

The vbseo folks suggested changing the htaccess in the /forums directory to something like this:

Code: Select all
RewriteEngine On
#RewriteCond %{HTTP_HOST} ^domain.com [NC]
#RewriteRule ^(.*)$ http://www.domain.com/forums/$1 [L,R=301]

RewriteRule ^((urllist|sitemap).*\.(xml|txt)(\.gz)?)$ vbseo_sitemap/vbseo_getsitemap.php?sitemap=$1 [L]


But it did not work at all; caused a server error. Any advice would be greatly appreciated.
aciurczak
 
Posts: 3
Joined: Sat Jan 10, 2009 12:34 am

Postby richardk » Sun Jan 11, 2009 12:54 pm

/.htaccess
Code: Select all
Options +FollowSymLinks

RewriteEngine On

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

and /forums/.htaccess
Code: Select all
Options +FollowSymLinks

RewriteEngine On

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

RewriteRule ^((urllist|sitemap).*\.(xml|txt)(\.gz)?)$ vbseo_sitemap/vbseo_getsitemap.php?sitemap=$1 [L]

should be fine.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby aciurczak » Sun Jan 11, 2009 1:38 pm

Looks like this is working perfectly! Thanks so much.

I'll now add it for the rest of the domains on the same site, but I don't expect an issue.

Really appreciate the help, this was the one place on the net that gave me a solution that worked, and I've spent a whole pile of hours working on this problem.
aciurczak
 
Posts: 3
Joined: Sat Jan 10, 2009 12:34 am


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 15 guests

cron