I got the rewrite for visitors who go to mysite.com to be redirected to www.mysite.com and it works fine. The problem is that I cannot get this to work for a specific directory. I want users who navigate to mysite.com/directory to be redirected to www.mysite.com/directory. This is what I have in that specific directory's .htaccess (not my root's .htaccess): # Non-www to WWW RewriteCond %{HTTP_HOST} !^www\.mysite\.com\.directory[NC] RewriteRule (.*) http://www.mysite.com/directory/$1 [R=301,L] Code (markup): And for some reason, this results in a browser error telling me it is resulting in an infinite loop that will never end. Why is that? How do I fix it? Thanks
Unfortunately, this doesn't work. I'd prefer if I could control just one specific directory of the domain, because my root is a WordPress blog, so it automatically redirects to the WWW version using the permalink settings. Is there a code I can place in the .htaccess of /directory (not the root) to redirect it to the WWW version? Thanks for your help
Hey NickR25, you can place the following code into your .htaccess file RewriteEngine On RewriteCond %{HTTP_HOST} ^example.com RewriteRule (.*) http://www.example.com/$1 [R=301,L] this will definatly work as its working on my server
Hi, You can also do something a bit more generic like RewriteEngine On RewriteCond %{HTTP_HOST} !^www\..* [NC] RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]
is there an error in this line RewriteCond %{HTTP_HOST} !^www\.mysite\.com\.directory[NC] must be a slash? RewriteCond %{HTTP_HOST} !^www\.mysite\.com\/directory[NC]
None of the ones that have been posted in this thread work. Remember, I am wanting to redirect a specific directory only; not any URL. In other words, I want mysite.com/directory to redirect to www.mysite.com/directory, but I do not want mysite.com to redirect to www.mysite.com. Edit: Actually, I think we have a winner This worked when I placed it in my /directory: RewriteEngine On RewriteCond %{HTTP_HOST} !^www\..* [NC] RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/directory/$1 [R=301,L] Code (markup):
Update: It was working at first, but I just realized it no longer works. It tries to take me to www.mysite.com/hsphere/local/home/*****/mysite.com/directory Why is that and how do I correct it?
How about: RewriteEngine On RewriteCond %{HTTP_HOST} !^www\..* [NC] RewriteCond %{REQUEST_URI} ^/directory [NC] RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] Code (markup):