Forum Moderators: phranque

Message Too Old, No Replies

Stopping a .htaccess file from applying to specific directories

Override htaccess for sub-directories

         

Andrew_Sam

10:28 pm on Aug 13, 2005 (gmt 0)

10+ Year Member



How do folks?

I have three Websites hosted by my ISP each each stored in it's own subdirectory off the root. I recently had to add an htaccess file to this root directory to redirect users from an old website address to a new domain I had purchased (again hosted in a sub-directory).

However this htaccess file is now applying site-wide and across all aliases meaning all three of my sites now point to just one site

As I understand htaccess files cascade downwards, so that if I have a .htaccess file in my root directory, /,
and another in a sub-directory called /Wright, then when a file is requested from the /Wright directory Apache will merge the two files and use all the directives.

Is there any way I can stop this behaviour - I have a 301 redirect in my root directory and I don’t want it to apply to the /Wright sub-directory. I have tried unsuccessfully putting a 301 redirect in the /Wright sub-directory to override the root but this has not been successful.

I tried another .htaccess file in one of the sub-directories housing one of the affected sites, but all that happened when I tried visiting the affected url was the browser hung. It kept trying to open the page but eventually timed out.

Also (just to complicate things) I should add that the document root of my old Website and the overall root were the same.

Thanks in hopeful anticipation folks

jdMorgan

11:28 pm on Aug 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Andrew_Sam,

Welcome to WebmasterWorld!

Please post the relevant code and describe its function so we can discuss it.

The easiest fix is most likely to be a matter of simply adding some exclusions to your rule(s) using RewriteCond testing server variable(s) %{HTTP_HOST} and/or %{REQUEST_URI}.

Jim

Andrew_Sam

9:10 pm on Aug 14, 2005 (gmt 0)

10+ Year Member



JDMorgan
Thanks for the reply and welcome.

My overall root directory is /htdocs

However this was also the site root for my old Website namely http://www.danny.example.co.uk

I have now moved this site’s contents to a new sub directory called danny i.e. /htdocs/danny and my new domain of http://www.tree.example.co.uk points to this.

I have a .htacess file with the contents below successfully redirecting from http://www.danny.example.co.uk to http://www.tree.example.co.uk

redirect 301 /index.htm http://www.tree.example.co.uk/

My problem is that two further websites of mine each hosted in their own sub-directory i.e. /htdocs/right and /htdocs/nick have both started redirecting to http://www.tree.example.co.uk since the working .htacess file on www.tree.example.co.uk was implemented.

Thanks

[edited by: jdMorgan at 2:12 pm (utc) on Aug. 15, 2005]
[edit reason] Removed specifics per TOS. De-linked. [/edit]

jdMorgan

2:14 pm on Aug 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The problem is that mod_alias' Redirect directive is unconditional. Try using mod_rewrite instead, and then see my note above about adding an HTTP_HOST exclusion to prevent the rule from affecting the other domains.

Jim

Andrew_Sam

8:31 pm on Aug 15, 2005 (gmt 0)

10+ Year Member



Many thanks again for replying JD
I'm really embarrassed to say I'm well and truly lost.
I don't know what a mod_rewrite is let alone how to create one and as for HTTP_HOST exclusion :(

Would it please be possible to explain the above in basic terms?

jdMorgan

9:43 pm on Aug 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Andrew_Sam,

Start with the reference documents cited in our forum charter [webmasterworld.com]. Reading the charter will also help you to get the most out of this forum. There are also two [webmasterworld.com] posts [webmasterworld.com] in the library [webmasterworld.com] that will help you get started.

Jim