I'm moving a site to a new shared host. I want to have a folder of php includes below the live directory and available to public php pages. What directives should I add to the .htaccess file in www_public?

The basic should be some version of mod_rewrite for www_public/index.* www_my_new_public/index.*, yes?

Mod_alias will send all traffic to one directory to another directory, yes? Should I do that instead?

Most posts I'm finding on the apache url mods reference cleaning up URLs of dot-php. or redirecting old content to a new location. I could really use some advice to know what to be looking for.

1 Answer 1


You don't have to make it that complicated - if you only have a folder for include files which you don't want accessible, make a .htaccess inside it with the following code:

Order allow,deny
Deny from all

And that should fix the issue - then you can simply change the DocumentRoot of your web site.. If you still want to make the redirection, use mod rewrite and something like that (not tested, but it's close to what you need):

RewriteCond %{REQUEST_URI} !^/www_my_new_public/.* [NC]
RewriteRule ^(.*)$ http://your.domain.name/www_my_new_public/$1
  • While I subscribe to KISS and making the includes folder inaccessible is simpler, I do not know what I will do in the future. Therefore the "real" solution is to make a sub-folder of my www-public the new-www-public. And by the looks of this code, its not that complicated...
    – xtian
    Aug 15, 2011 at 13:39
  • And, 1) What's the difference between this and Alias URL-path directory-path? 2) Can I simply add a third line in the above example to rewrite the URL, RewriteRule http://your.domain.name/www_my_new_public/$1 http://your.domain.name/$1?
    – xtian
    Aug 15, 2011 at 14:29
  • Tested. It does indeed work. To accommodate sub-domains and URLs without www.*, should I work on rewriting the RegEx of the above example? Or should I look to writing additional special case rules?
    – xtian
    Aug 15, 2011 at 20:26
  • It's a point of start from which you can start developing according to your needs.
    – O G
    Aug 16, 2011 at 4:18
  • And yet, I am asking for advise to understand how these common use cases are best addressed so I don't spend half the day attempting to do something impossible or not "best practice".
    – xtian
    Aug 16, 2011 at 21:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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