load up an htaccess file thats in another directory not in the DocumentRoot - .htaccess

Is it possible to apply htaccess rules that are located in another directory.
for example
/folder
--|__ .htaccess
--|__ /htdocs
--------|__ index.php
the DocumentRoot is htdocs, while the htaccess file is located outside of that.
Can I access that htaccess file?

Edit: .htaccess rules apply to subdirectories too, so yes, you can place the file one level above htdocs. The rules in it will apply.

Related

.htaccess rules to ignore the main directory .htaccess file if specific subfolder is requested in URI

I have three subfolders /software1/, /software2/ and /software3/ for three different applications in the main root directory for domain.com. The .htaccess rules for these subfolders are interfering with the .htaccess file in the main directory. So, I wonder if there is a rule to add into the .htaccess file in the main directory to ignore the rest of the file and directly jump into the /software1/, /software2/ and /software3/ subfolders (i.e. their .htaccess files) if URI is http://domain.com/software1/..., http://domain.com/software2/... and http://domain.com/software3/...?
It would have been nice to see your current .htaccess rules so we can see what it's doing or not doing. But if you just want to not do anything for the 3 directories, you can try this in the main .htaccess and just have it not do anything if it is one of those 3 directories.
RewriteEngine On
RewriteRule ^(software1|software2|software3)$ - [L,NC]

htaccess file not working with wamp

I'm running WAMP on my Win7 box and trying to configure an htaccess folder to restrict my guests from browsing the directory structure.
Right now, if you head to http://grovertechnologysolutions.com/Technical, it will list the directory structure which I do not want. They should be only able to get to the .html site.
I've already modified the httpd.conf file to remove the commented out rewrite mod.
I've added the htaccess file to the documentroot of my website.
My htaccess file looks like this:
options -indexes
# or #
IndexIgnore *
I've restarted all services multiple times.
Should the htaccess be in the WWW folder or the document root? I run many websites virtually and only care about my main site, so I've been placing the htaccess inside that folder, but have tried www as well.
I'm assuming you've edited the proper .htaccess file in the website's DocumentRoot folder.
Options -Indexes
The above will only work if your particular WAMP's configuration and the website's VirtualHost file has the proper AllowOverride value set, such as...
AllowOverride All
Check the website's VirtualHost file, and/or httpd.conf's for something like...
<Directory "C:/WampDeveloper/Websites/www.example.com/webroot">
Options All
AllowOverride All
order allow,deny
allow from all
</Directory>
If it's not set to All nor lists Indexes, that .htaccess line is going to get ignored.
I've already modified the httpd.conf file to remove the commented out rewrite mod
mod_rewrite has nothing to do with this.
I've restarted all services multiple times.
.htaccess files are re-read on every request. You don't need to restart Apache.
http://httpd.apache.org/docs/2.2/mod/core.html#allowoverride

mod_rewrite: rewriting existing directory with htaccess in it

how can I tell mod_rewrite that ALL existing directories should be rewritten?
I have an subdirectory with a .htaccess-File which rewrites too. When I go to domian.tld/sub_with_htaccess, Apache only reads the htaccess in "sub_with_htaccess" but do not read the .htaccess in / which is more important for me.
BUT: When I have a subdomain (sub.domain.tld) whose document root points on /var/www/domain-tld/sub_with_htaccess, I want that only the .htaccess in "sub_with_htaccess" decides what to do.
Any ideas? :)
You can try adding the RewriteOption directive in the htaccess file in the sub_with_htaccess directory:
RewriteOption Inherit
This will make it so rules from parent directories get appended after the rules in this htaccess file. If you are using apache 2.4, you can also use the InheritBefore option which will place the parent htaccess' mod_rewrite rules before the rules in this htaccess file.

How to disable effects of .htaccess within a subfolder if there is a .htaccess file in root?

In my application I have separate spaces for user and admin like
if www.example.com is my website, then www.example.com/admin is my admin URL.
I am using a .htaccess file in my root, and it affects some of the functionality in my admin folder, which I don't want to.
For example, consider below is my folder structure
..
.htaccess
index.php
admin
So if I don't want the .htaccess rules to apply within the admin folder, is there any way?
For people that don't have direct access to httpd.conf (shared hosting for example), just put another .htaccess file in the subfolder and set to the desired behavior.
You should be able to do this, but it does require write access to the httpd.conf configuration.
If you have access to the httpd.conf file, something like
<Directory /admin>
AllowOverride None
</Directory
should do the trick.
Also, note that using .htaccess files in the root directory (as you said you did) is not a recommended approach. You'd be better off moving the contents of the htaccess file into the proper contexts of the httpd.conf file.
More information can be found at http://httpd.apache.org/docs/2.2/mod/core.html#allowoverride

Multiple htaccess files with different rewrite rules

I have 2 .htaccess files - one in root directory, another in subdirectory:
accordingly docroot/ and /subdirectory/docroot (this one works like a separate account).
The problem is that there are different rewrite rules in both files. Basicly, the problem is that the .htaccess in subdirectory doesn't work and/or is ignored.
What I am trying to achieve is to have one set of rewrite rules for docroot and other set of rewrite rules for subdirectory/docroot
edit:
the .htaccess file in subdirectory/docroot basicly strips index.php from url, and it actually works, but when i go to subdirectory/user it redirects to subdirectory/user/login (instead of subdirectory/index.php/user/login -- this parts is ok) but the website shows the root page (not subdirectory, but domain root)
Any ideas?
I just had to set RewriteBase to that particular subdirectory to make things work.

Resources