1

I'm trying to remove the www. for a single directory called dir (for example). I need to be able to do this from the .htaccess file in that directory. (I don't have root access.) Any idea how to make this work?

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

Update—the solution:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/dir/$1 [R=301,L]
ryanve
  • 50,076
  • 30
  • 102
  • 137

1 Answers1

2

The HTTP_HOST will not contain the path being accessed you need to match that in the rewrite rule itself:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule ^dir\/(.*)$ http://example.com/dir/$1 [R=301,L]
Charles Keepax
  • 2,392
  • 1
  • 18
  • 19
  • The makes perfect sense—thank you! I still didn't get it to work though...updating the question. – ryanve Jul 10 '11 at 16:50
  • Got it! Because I'm using the .htaccess in /dir/ I don't need 'dir' in the first part of the RewriteRule (like I would if in the root level .htaccess). Thanks again :) – ryanve Jul 10 '11 at 17:02