Forum Moderators: phranque

Message Too Old, No Replies

Mod Rewrite Hide Folder

Hiding folder with htaccess

         

TeamSDA

4:29 am on Dec 5, 2011 (gmt 0)

10+ Year Member



Hi All,

How do you hide a folder using htaccess.

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

The folder needs to alway be hidden. I've tried the code below in my htaccess file but it didn't work. Any suggestions.



RewriteEngine on

#RewriteRule ^/(.*)$ /pages/$1




Christian

g1smd

7:39 am on Dec 5, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You hide a folder by linking to the URL that you want users to see and use, then adding a rewrite (using a RewriteRule) to fetch the content from the real folder without revealing what that location is.

You also add a redirect (using a RewriteRule) so that if someone asks for the old URL they are redirected to the new one. This rule needs a RewriteCond looking at THE_REQUEST to avoid an infinite rewrite-redirect loop.

www.example.com/pages/index.php to www.example.com/index.php

Never include a named index file in the URL. The correct URL ends with a slash.

Redirect www.example.com/pages/index.php to www.website.com/
Redirect www.example.com/index.php to www.website.com/
Rewrite www.example.com/ to /pages/index.php

Didn't work

Because it's broken. Without further information it's all guesswork.

What did it actually do? Use the Live HTTP Headers extension for Firefox to investigate.

URL paths are "localised" "per directory" "in htaccess context" before being presented to mod_rewrite. The leading slash in your pattern is incorrect if this rule is in your .htaccess file.

(.*) means everything. Mod_rewrite runs again and again until all rules are satisfied.

You'll need a RewriteCond to exclude already rewritten requests.

Every RewriteRule should have the [L] flag. Add it.

Use example.com in code examples in this forum.