SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Dec 2006
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Dynamically modifying htaccess through rails

    I would like to be able to write directly to the htaccess file by using rails. Being new to the framework and language I don't yet know of anything which is equivalent to PHP's fwrite function which would achieve this.
    Does such a function exist?
    I aim to allow each user who registers access to an image through a url which they have chosen and modifying htaccess seems to me to be the easiest way to restrict access to images.
    Thanks for any help

  2. #2
    SitePoint Addict
    Join Date
    Mar 2005
    Posts
    251
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to use the ruby core File class. The documentation is available here....
    http://www.ruby-doc.org/core/classes/File.html

  3. #3
    SitePoint Guru 33degrees's Avatar
    Join Date
    May 2005
    Posts
    707
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Modifying the .htaccess is probably not the way to go about it; it will quickly become unwieldy, not to mention slow, as apache has to run all the rules against every single request. What exactly are you trying to do?

  4. #4
    SitePoint Member
    Join Date
    Dec 2006
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm trying to limit the access of each user to a single image assigned to each of them, through a referrer of their choice.
    All the referrers would originate from one domain, although would vary depending on the subfolders.

    I managed to add some rewrite conditions to htaccess on signup using syswrite, but it would be very hard to cleanup if I ever wished to remove users and if theres a more efficient way im all for it.

  5. #5
    SitePoint Addict myrdhrin's Avatar
    Join Date
    Jul 2004
    Location
    Montreal
    Posts
    211
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you thought you could control access to the image using a Rails controller? The method send_file of the ActionController can be pretty useful in that kind of situation

    OR

    instead of playing with the .htaccess file you might consider writing your rewrite rule in the .htaccess using the RewriteMap instruction Apache provides. This way you can maintain atext file external to the .htaccess or even link it to your ruby script directly
    Jean-Marc (aka Myrdhrin)
    M2i3 - blog - Protect your privacy with Zliki

  6. #6
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Couldn't you write one rule in your htaccess that says that:

    Code:
    site.com/images/theimage
    is rewritten to this:

    Code:
    site.com/where-the-images-are-stored/theimage.png
    Or do you need arbitrary urls?

    You could use Rails' routing to do this, along with myrdhrin's send_file suggestion.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •