Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stoping a .htacess file from applying to sub-directories?

Status
Not open for further replies.

AndrewSam

Technical User
Aug 7, 2005
4
GB
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.

Thanks in hopeful anticipation folks
 
This is normal for any directive. It applies to all subdirectories under it unless the directive is redefined. This would mean you can use the directive AllowOverride and set it to none.

 
RA

In very basic terms how can I redefine the directive?
I've never heard of a "Directive Allow Override".
Cheers
 
Sorry - to redefine a directive means to use it again later or in this case, farther down the tree. To use .htaccess, your isp used the AllowOverride directive that probably was set to "all". This way it could be used as a way to secure your directories with authentication such as user/password or to configure your directories without having to restart apache. If you are not familiar with apache's directives, you can read the docs at
 
RhythmAce

If I'm reading this right you're saying that to stop the redirect applying to subdirectories you have to add another htaccess file with a redirect in it to the affected sub-directories (ie.wright) which overwrites the one in the root?

I tried that but the affected website address just hangs, seemingly trying to open the page, then timing out "Internet Explorer was unable to link to the Web page you requested. The page might be temporarily unavailable"? :(

 
Make a copy of your .htaccess and put it in the sub-directory you want it to work in - not your root. It should be in the DocumentRoot of the site you want redirected. Then rename the original .htaccess something else but something you'll remember. This way, if things go south, you can always get back to where you were. Just in case this is all new to you, the DocumentRoot is the directory where the html files for each website are stored. In most cases it's either html, htdocs or public_html. If you're really interested, you can find more info at
 
RhythmAce

I think the complication is that the document root of my old Website and the overall root were the same.
 
If that is the case, it sure as heck would be the problem. Each site should have it's on directory. The would be its webspace or root "/". Inside each site's root dir you might find the DocumentRoots, usually called htdocs or html. You might also see cgi-bin and logs. Most hosting providers put sub-domains inside your DocumentRoot and other domains you own inside your root directory. This way it is easier to set up an ftp account because your root directory becomes your home directory and you are chrooted to it which means you can't cruise all over the hosting provider's server. The funky thing about this is your first site is one level higher than the rest. For example, if your hosting provider add two more sites to your account, they will be in your root directory allong with your /html directory. I'll try to draw a picture but I'm not sure how it will turn out.

/MainRootDir - /html
- /cgi-bin
- /logs
- /site2 - /html
- /cgi-bin
- /logs
- /site3 - /html
- /cgi-bin
- /logs

Yours may be a little different but I hope you get the idea. I didn't do the sub-domains but it would look the same only they would be inside the html directories.



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top