Forum Moderators: phranque
I tried inserting the following into my .htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mysite\.com [nc]
RewriteRule (.*) [mysite.com...] [R=301,L]
But this didn't handle files located in my subdirecties such as [mysite.com...] would redirect to [mysite.com...] and not [mysite.com...]
Does anybody know what I'm doing wrong, and what I need to do to enable www rewriting for my webfiles?
If it worked for your top-level directory, then try adding
RewriteOptions inherit
Otherwise, you'll need to contact your host, as the server configuration is either incorrect, or is interfering with your domain redirect.
Jim
It turns out my problem was that I had my .htaccess under [mysite.com...] and not [mysite.com....] Once I changed this everything worked even though my requested file was under 'mydirectory'...
Does anybody know if this means you can't then via .htaccess add subdomains to exclusive directories then?
However, you can do pretty much whatever you want to do in translating URLs to filepaths as long as you can put the code in a place where it will be executed for the relevant requests. This would be in any HTTP-accessible directory between and including the top-level directory 'pointed to' by the (sub)domain, and the subdirectory in which the affected files reside. Apache does a simple directory-walk to find .htaccess files that apply to the current request.
For the URL /pages/widgets/green/fuzzy/widget03.html, the server would check the root directory "/", then /pages/, then /pages/widgets/, then /pages/widgets/green/, and finally, /pages/widgets/green/fuzzy/ for the existence of .htaccess files. The setting of RewriteOptions inherit then affects how rewriterules in these .htaccess files would be applied.
The key is in putting the code somewhere in the directory-path to the requested file(s) so that it can run and change the URL-to-filename mapping.
Jim
at what level are you putting the .htaccess , is it also avaliable inside mydirectory folder?Initially, I put it in a subdirectory just to test that it worked (I didn't want to mess up my entire site with bad .htaccess directives) and when I put in the webroot, it worked as needed (which was to add the www to avoid split page ranks).