Directory Redirect with .htaccess

Posted on 2011-10-30
Last Modified: 2012-05-12
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?
Question by:davideo7
    LVL 76

    Accepted Solution

    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?

    LVL 19

    Assisted Solution

    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


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
    I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now