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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RE: How to make certain additions to an .htaccess file

Status
Not open for further replies.

darrellblackhawk

Programmer
Aug 30, 2002
846
0
0
US
Hello,

I have an .htaccess file that I'm using as a the base of router on a client site.

Code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

As you can see, it will route all requests for non-existent files to: index.php.

What I'd like to add in addition, is the ability to restrict access to specific sub-directories in the directory that this .htaccess file is located in.

Also, I'd like to allow certain IP's to allow a select set of files in these restricted sub-directories.

Thanks much in advance.
 
Correction in my original post.

This should say:

Also, I'd like to allow certain IP's access to a select set of files in these restricted sub-directories.
 
The .htaccess file was designed to let users who do not have access to httpd.conf to still be able to control how apache works whith the confines of their own webspace. This means you can use almost any directive apache has in your .htaccess file. The scope of each directive is the same as it is in httpd.conf. So if you have an .htaccess file in any given directory, then directives in that .htaccess file will pertain to that directory and all its sub-directories. For example, let's say you have a sub-directory called /private off of your DocumentRoot. And There are subs off of /rivate that you want to allow access to. If access is to be the same ip address for all sub-directories, then create an htaccess file in /private and insert the fllowing:

Code:
Order allow, deny
allow from 192.160.1.20

This tells apache to parse the allow statements before the deny statements and set the default state to deny. Now that apache is denying from everyone, you tell it to allow only from 192.168.1.20. As I said, this will pertain to /rivate and all its subs. If you need different ip addresses to have access to different directories, then create a different .htaccess file for each of those. Another way is to use directory containers for each directory and use the Order directive in each of those.



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top