[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 249
  • Last Modified:

Directory Redirect with .htaccess

Have a game on my site which stores save files/folders all in the same directory (I say save file/folder because each user has their own folder and within that folder contains their save files).  My site is on a linux computer but I recently discovered that there's a 31,998 folder limit for each directory which means there's no more room for more files/folders to be saved.  

Since the game has already been hardcoded to store the files/folders into a specific directory, I was wondering if it was possible with .htaccess to redirect them to a different folder based on the users ID.  So example:

Currently they all go to vizzedboard/retro/saves
I'd want Users with ID 1-10,000 to go to vizzedboard/retro/saves/saves1
I'd want Users with ID 10,001-20,000 to go to vizzedboard/retro/saves/saves2
And so on

The names of the files/folders are titled after the users ID.

Is this possible?
2 Solutions
You could create sym links for directories.
htaccess deals with granting access through the web browser.  Not sure what or how you are looking to redirect given the application will and does not conform to the settings within .htaccess.
Do you have the source such that you can alter the mechanism by which new additions are done, or adjust the storage mechanism to further segment how the data/files/directories are created/stored?

You cannot redirect based on UID via .htaccess, because htaccess doesn't have any knowledge of Unix uid/gids - the authentication system is totally separate, and uses its own htpasswd (or SQL, if you're using mod_auth_mysql) but not /etc/passwd|shadow

If your system uses PHP, this is pretty trivial though.  The code below should do what you want if your site supports PHP.  Note, you will need the php-process package to support the posix functionality.

What it does is find the user's UID from the system password file, divides it by 10000 to get the final save path, and concatenates it to the base location.  Then it uses the Header() function to physically redirect the user to the new location.




Header("Location: $redirloc");


Open in new window


Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now