views:

308

answers:

2

I think this is a pretty simple question.

How do you an apache rewrite to hide a folder.

EX: www.website.com/pages/login.php to www.website.com/login.php

or www.website.com/pages/home.php to www.website.com/home.php

The folder needs to alway be hidden. thanks

+2  A: 

I assume what you want is for the browser to request /home.php but the server to actually use the file located at /pages/home.php, right? If so, this should work:

Make sure the apache mod_rewrite module is installed. Then, use something like this in your apache config, virtual host config, or (less desirable) .htaccess file:

RewriteEngine On
RewriteRule ^/(.*)$   /pages/$1

The rules use regular expressions, so you may want to look at a reference on that topic if you're unsure. Read the manual for more info on other directives (RewriteCond can be very useful) or rule options.

grossvogel
A: 

If your example actually reflects the files you need, then in your .htaccess file:

#Options +FollowSymLinks
RewriteEngine On

RewriteRule ^/pages/(.+)\.php $1\.php [NC, L]

Also, if the directory has read permission, it cannot be, in reality "hidden". I assume you mean that it no longer appears in the url.

TMG
This is what I had at first, too. But this means the user would see /pages/home.php in the address bar, while the server would serve up /home.php. After rethinking, I think the OP wants the opposite...
grossvogel
@grossvogel - you're right - I re-read his question more closely.
TMG