1

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.

xtian
  • 321
  • 3
  • 15

1 Answers1

0

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
O G
  • 874
  • 4
  • 6
  • 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 '11 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 '11 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 '11 at 20:26
  • It's a point of start from which you can start developing according to your needs. – O G Aug 16 '11 at 04: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 '11 at 21:27
  • I was reviewing my host's knowledgebase and forum for solutions to this problem and noticed users requesting this solution were frequently reseller accounts (parking to a single page). I am most definitely not reselling my domain. AND the solution above works only for the first level directory. Linking to a sub-directory rewrites the new_public incorrectly, breaking the links. – xtian Aug 21 '11 at 17:09