Forum Moderators: phranque
I'm using .htaccess to redirect "non-www" entries to www, like "mysite.com" to "http://www.mysite.com". I also wanted to block hot-linking of some file types in some of the subdirectories. Since I have multiple subdirectories, some with photos and some without, I have a root .htaccess file and an .htaccess file in some of the subdirectories.
The root .htaccess file on my server includes these lines:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mysite\.com [NC]
RewriteRule (.*) [mysite.com...] [R=301,L]
This redirects the main URL correctly, so if someone enters "mysite.com" they get redirected to "http://www.mysite.com.
But it does not seem to add the "www" to the incorrectly entered subdirectory URLs.
So if someone enters:
"mysite.com/cats/persian/persian-cats.html"
they get:
"http://mysite.com/cats/persian/persian-cats.html"
instead of
"http://www.mysite.com/cats/persian/persian-cats.html"
I've even tried placing an .htaccess file with just the redirect code above in the subdirectories, but it still does not redirect the "non-www" subdirectory entries to the "www" form.
So my question is, how can I get the "non-www" redirect to work for all of the longer subdirectory pathnames also? Is there a subdirectory or path wildcard or something I'm missing in the code above that would tell .htaccess to add the "www" in any pathname?
I've searched all over but can not find an answer, sorry if I missed it?
Thanks..!
However, your server may not be configured so that child subdirectories inherit the mod_rewrite rules of their parents, or you may have other modules interfering.
I suggest disabling MultiViews if you're not using content negotiation, and adding
RewriteOptions Inherit
If this does not help, ask your host to turn off "UseCanonicalName" in the server config.
Jim
Not sure about the Multiviews though, here's the entry in my httpd.conf, I'm not sure if this is on or off (looks like it's on?) and what I should change to turn it off?:
<Directory "/usr/local/apache/icons">
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
Thanks...!
So the Options doc says to put a "-" sign to turn it off, just want to check, as I have limited experience, would the way I have it below turn off the ability to index and the MultiViews?
The documentation appears to say not to use only 1 "-" sign, so I figured I'd turn both off?
The only problem here is this is the only place in my httpd.conf file where the word "MultiViews" appears, but I'm not sure if this directory it's pointing to (/usr/local/apache/icons) will do the trick for me:
<Directory "/usr/local/apache/icons">
Options -Indexes -MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
Thanks again for your help!
I encourage you to test things and see what they do, rather than waiting around here for answers which might take hours. It's faster and you may learn something. Also, I'm not aware of any directives that will actually cause the server to burst into flames (that feature won't be available until Apache 3.x Beta at the earliest), so just keep a backup of any changes you make, and you'll be fine... :)
Jim
How anybody gets anything done with Apache servers is beyond me, considering the obscurity of the information. Definitely not written for someone who only has to dabble in it once and a while! ;-)