You can just create a .htaccess with
DENY FROM ALL
for the folders (put the file it in those).
Also with mod_rewrite on www/.htaccess:
RewriteEngine On
RewriteRule ^(secret1|secret2|asdf) - [F,L]
OK, so you want to restrict access to private
projects by IP address, and you have the following directory structure:
DocumentRoot
is /var/www
- public projects are under
/var/www/public
- private projects are under
/var/www/private
So, in your Apache configuration file (httpd.conf
) add a <Directory>
directive like:
<Directory /var/www/private>
Order deny,allow
Deny from all
Allow from 10.0.0.0/24
</Directory>
and everything under that directory will only be accessible if you're coming from the allowed network(s). (There are other ways to specify the Allow
ed hosts too).
My domain is www.example.com
.
I want to reach /var/www/html/public/publicproj1
as www.example.com/publicproj1
and
/var/www/html/private/privateproj1
as www.example.com/privateproj1
This is a bit harder. You're going to need rewrite rules or an Alias
directive for each project. As you noted that's not an ideal situation, so let's look at some other options.
Configured as I described above with the directory structure you have you'll be able to access the directories as www.example.com/public/proj1
and www.example.com/private/proj1
out of the box.
If that works for you you're done.
If that's not a good enough solution, consider moving your public projects so they're directly under /var/www/html
-- your public projects would then be accessible as www.example.com/publicproj1
, and your private projects would be accessible with the /private/
bit added in. (Presumably you don't care so much about a little ugly in the URL of a "private" project, and this avoids the need to do any Alias
ing for your public stuff).
Regarding the starting page, you can show content of startingpage
folder if www.example.com
is requested with the following rules:
RewriteEngine On
# Don't apply to URLs that go to existing files or folders.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Only apply to URLs that aren't already under folder.
RewriteCond %{REQUEST_URI} !^/startingpage/
RewriteRule ^(.*)$ /startingpage/$1
Best Answer
You can just put a
.htaccess
in every Directory you don't want to get accessed with this content: