I’m looking to create an admin backend for a website and I’d like each administrator to have their own personal URL to their admin folder which they can specify upon registration, the folder name they type will then be saved in a MySQL database.
I’d then like a .htaccess file to be able to read the URL a user enters and if it’s in a users ‘admin folder’ field in the database it’ll rewrite a folder name (for this examplpe we’ll call it ‘admin’) so the user can use their own URL from the database but redirect them to /admin.
For example..
Username – Folder name
richard – myhiddenfolder
A .htaccess file should then grab the current logged in users folder name (set by something like $_SESSION['folder_name']) and load /admin, still displaying the users folder name in the browsers address bar.
Edit
Sorry, my overall question is, how can I grab the session var ‘folder_name’ and parse it in the .htaccess file to rewrite a folder called ‘admin’.
Technically something like that is possible using either mod_rewrite or just plain ol’ symlinks (if you got the permissions to do so).
If you go with mod_rewrite, you’ll find RewriteMap convinient. However, declarations of RewriteMaps cannot be made in a per-directory Context (this includes .htaccess files), so you need to change the http servers configuration, which is probably not what you want.
You could still change the .htaccess from within your php script each time a user changes his custom folder name. You would then generate rules like:
This requires the custom path to be set as a cookie. Sadly, there is no way to refer to the cookies value in the RewriteRule test (only in the substitition which is not what we want).
Also make sure that the custom paths do not conflict with any real paths, as that would break the site for the corresponding user.
For symlinks, every time a user changes his admin folders name, you create/remove/update the symlink for him. Of course you still had to check for admin permissions in the admin scripts, as the symlinks are global.
Independent from which method you choose, make sure you check for admin privilegues in your admin scripts.
Edit:
My reply was a little too early for the edited question, so an answer to that would be: It’s not possible to directly access php session data from within an .htaccess. You could try to play around with prg: RewriteMaps though.