Forum Moderators: phranque

Message Too Old, No Replies

How to add the www subdomain's for reqests?

         

smithaa02

7:26 pm on Jan 23, 2006 (gmt 0)

10+ Year Member



Basically, what I what is for requests for [mysite.com...] to be redirected to [mysite.com....]

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?

jdMorgan

7:30 pm on Jan 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your code should have worked as-written.

If it worked for your top-level directory, then try adding


RewriteOptions inherit

after RewriteEngine on, first to the same .htaccess file, and then (if needed) to the .htaccess files in your subdirectories.

Otherwise, you'll need to contact your host, as the server configuration is either incorrect, or is interfering with your domain redirect.

Jim

smithaa02

7:43 pm on Jan 23, 2006 (gmt 0)

10+ Year Member



Thank you jdMorgan for you prompt response.

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?

jdMorgan

8:03 pm on Jan 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Once a subdomain is resolved to a particular server directory path, then 'subdomain' has no further meaning to the server. In other words, subdomains exist in URL-space, and not in filesystem-space. Therefore, your question appears to be a non-sequitur.

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

AjiNIMC

2:45 am on Jan 25, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



at what level are you putting the .htaccess , is it also avaliable inside mydirectory folder?

smithaa02

2:45 pm on Jan 25, 2006 (gmt 0)

10+ Year Member



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).