Forum Moderators: phranque
RewriteCond %{HTTP_HOST} ^www\.example\.com
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
This obviously was meant to remove the www's from our domain name, and it worked great for months.
Then, the other day, I had to add a .htaccess file to a sub-directory - call it subdir. This .htaccess file has a few of its own redirects, simple things, like this:
RewriteRule ^(.*)011$ http://example.com/subdir/myscript.php?id=011$1 [R=301]
Ever since adding the second .htaccess file to the /subdir sub-directory, my root-level .htaccess file hasn't been rewriting www URL's for pages within the sub-directory. For example: http://www.example.com/subdir/about.html should get rewritten to just http://example.com/subdir/about.html. But instead, if you visit the page with the w's, they stay in place.
What's the issue here, and how should I go about trying to fix it?
Thanks in advance,
Matthew
See RewriteOptions [httpd.apache.org] inherit.
If it is not set by default on your server, the behaviour you are seeing would be expected.
Jim
RewriteOptions inherit
...to the /subdir .htaccess file didn't seem to have any effect. I tested several times, clearing my browser cache each time and removing rewrite rules from the /subdir .htaccess file, but it never did start applying the rewrite rules from the parent .htaccess file. Is this something the server administrator can disable, or did I do something wrong?
I managed to get halfway to what I need by adding two lines to the /subdir .htaccess file:
RewriteCond %{HTTP_HOST} ^www\.example\.com
RewriteRule ^(.*)$ http://example.com/subdir/$1 [R=301,L]
That correctly rewrites http://www.example.com/subdir/ to http://example.com/subdir/
But, it has the bizarre effect of rewriting http://www.example.com/subdir (no ending slash) to http://example.com//server/path/to/subdir (note the double slash).
I must be missing someting somewhere. And I suppose it's possible that there are other rewrite rules in my .htaccess file(s) that could be coming into play here, but none of them use the server path. Is there anything I'm clearly doing wrong, or would more information be helpful?
Thanks again,
Matthew
RewriteOptions inherit to the .htaccess file in /subdir and removing the rewrite rules does have an effect, but not the desired effect. It redirected http://www.example.com/subdir/ to http://example.com (no /subdir). I don't know why, given that the "no www" redirect rule I quoted in my first post, which is included in the parent directory, should (seemingly) redirect www.example.com/anydirectory to example.com/anydirectory. (And that's what it does for any directory that doesn't have its own .htaccess file.) I've been studying my eyes out on the Apache website but I can't make anything out of it. They seem to assume that you already know everything else about Apache, which I don't, so I have no framework to hang any of this knowledge on. Can anyone recommend a good book or tutorial that starts out basic and slowly works up to more advanced topics?
That indicates a problem elsewhere, possibly in the DocumentRoot [httpd.apache.org] declaration for the site. You might want to check with your host on this one...
Ask them to remove any trailing slash from the DocumentRoot declaration, and set RewriteOptions inherit for you.
Jim