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

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

Related

Redirect domain to subfolder, from subfolder

My friend's dad asked me to change the design of his website, so he gave me access to his account and I created a sub-folder where I uploaded the new design. The problem is that he has forgotten the password to his control panel and I only have access to the FTP in the sub-folder. I'm trying to redirect the domain (currently going to the root folder) to the sub-folder but since I don't have access to the root folder I'm finding it difficult to do so.
I've already tried a redirect with .htaccess but since I can only upload the file to my sub-folder, it thinks the redirect is to a sub-folder within that folder, instead of the folder inside the root.
TL;DR...
I want to redirect 'mydomain.com' to 'mydomain.com/folder' but only have access to the FTP in 'mydomain.com/folder'.
Thanks in advance!
.htaccess applies to the directory that contains it.
You cannot change this if you have not access to vhost.conf files (what would change the base dir of the site) or to the parent directory’s .htaccess.
You will need to:
Reset your dad’s friend’s password and forget this redirect, changing the existing web files (the cleanest way), or
change the .htaccess file in your parent's dad directory, adding this:
RewriteEngine on
RewriteRule ^/?(.*)$ dir2/$1 [R=301,L,P]
This should redirect the user to dir2, hiding that redirect in the urlbar.
h/t #Alejandro Teixeira Muñoz for the edits!

which are the valid .htaccess directories

Is there any need for .htaccess files in directories higher than that where index.html is placed?
I found such a file one level higher after a FileZilla accident (my fault; not Filezilla's) and suspect it should be deleted.
The .htaccess file has an effect on the directory it's in and all the descendent directories. You would need another .htaccess in a sub-folder if it was altering rules or adding new ones to what was inherited from its parent directory.
To expand on this based on more info from below: If the .htaccess files are in directories above your hosting dir, they will have an effect. However you should not amend or delete files on shared servers that you don't have direct authorization to. Check with your host or sysadmin - maybe those files need to be there, or perhaps they can be tidied up. In any case you can override .htaccess rules with a .htaccess file in the subdirectory.

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

deny from all in .htaccess not blocking file in the corresponding folder

I have an .htaccess file in the folder called folder and another file, called form.html in the same folder
When I try to reach the folder (by entering http://blablabla/folder/), it does block the access and I am getting an error 403 but when I enter the exact URL of the file http://blablabla/folder/form.html anf hit enter, I can access the file as easily as if I haven't put any .htaccess file.
Am I doing something wrong?
Am I missing something, should I use something like or
Sorry if the question is really basic...
.htaccess is a container for directives for your apache web server that apply to that directory and below only. What directives have you got in your .htaccess file?
The behaviour you outline above is how apache should behave with no .htaccess folder.
What is it that you are wanting to happen?

Share data between multiple .htaccess files

Ola there
I run several domains under the same shared hosting account, so I have the following files:
/home/joe/domain1.com/.htaccess
/home/joe/domain2.com/.htaccess
/home/joe/domain3.com/.htaccess
Each file contains duplicate data (stuff like deny from stupid.web.bot).
Is there any way to have a single file that's shared across multiple .htacess files? (something like bash's source command)
Use httpd.include vhost configuration files (as found in /etc/httpd/conf.d/vhosts.conf on RHEL systems) - these are preferable to .htaccess as they are loaded at server start and not dynamically, allowing .htaccess to be disabled and one less filesystem lookup required per directory lookup.
Not all configuration directives can be used in .htacess and httpd.include, check the manual for specifics. Directory commands are fine.
Use the include directive in your httpd.include to include a base config file with common rules.
If they just need to have exactly the same contents you could make a master.htaccess and just symlink it into each folder?
Specify the settings for all domains in your Apache configuration
<Directory /home/joe>
deny from stupid.web.bot
</Directory>
You can put a common .htaccess file in their parent directory: /home/joe.

Resources