Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top


  • I want to return a 404 page ("404.php") when a folder ("hidden") is accessed from the domain.
  • I want the same folder to be accessible from a subdomain ("") or from a different domain ("") which are both configured in a single VirtualHost entry.
  • The server has multiple IP addresses that it listens on. Each IP address serves identical content from the domain (sharing a VirtualHost entry.) I want the folder to be accessible from the IP address.
  • The server is configured to use SSL/TLS/HTTPS. HTTPS is optional on, but HTTPS is enforced in the .htaccess file for the hidden folder using a rewrite rule shown below.


RewriteCond %{HTTPS} !=on
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

I know that {SERVER_ADDR} gives the server's IP address, but does it return the one that the client is requesting from?

I'm also starting to think that something in the VirtualHosts file would be more appropriate. Any thoughts on this?

What should be allowed:

What should be 404-ed with 404.php


share|improve this question
up vote 1 down vote accepted

You can achieve this by adding some mod_rewrite magic to your .htaccess

RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule .* [R=301]
RewriteCond %{HTTPS} !=on
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

This is just an example of how can you do it, of course you can change the order of rules and the destination of them, just have in mind that adding the [L] will stop mod_rewrite from evaluating any further rules.

share|improve this answer
This almost fits my situation perfectly; thanks so much! – okw Feb 19 '11 at 4:15

this should work, as long as the DocumentRoot is not /www, but /www/something_else. Add this to your httpd.conf:


    DocumentRooot /www/hidden
    ServerAlias hidden
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.