.htaccess style rewrite with php

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Joe

    .htaccess style rewrite with php

    Hello, I currently have a file system where images and assets are
    stored in a directory like this:



    Which holds many differents clients assets, seperated by CLIENT_NAME.
    This is not very elegant when my clients want to provide links to
    their files, so I want a way of using php (or any other method you
    might suggest) to make the following work:



    This cannot be a simple redirect as that would not work for including
    files in htm templates. It has to do a similar thing as .htaccess
    rewrite, however I cannot use .htaccess since the client name is
    dynamic.

    Anybody any thoughts?
  • Sjoerd

    #2
    Re: .htaccess style rewrite with php

    On Aug 5, 11:09 am, Joe <j...@faceh.com wrote:When configured specifically, you can make a page media.php which is
    also used when

    is accessed. You can then parse the URL from the $_SERVER array.
    Anybody knows how this is called or configured?

    Of course, you can use rewriting to get rid of the .php, so that you
    rewrite
    media/bla to media.php/bla

    Now that I think of it, you can also rewrite
    media/bla to media.php?reque st=bla
    So that you can just get the request out of $_GET. However, this gives
    problems with some characters in filenames such as &.

    Comment

    • Joe

      #3
      Re: .htaccess style rewrite with php

      On Aug 5, 11:21 am, Sjoerd <sjoer...@gmail .comwrote:
      On Aug 5, 11:09 am, Joe <j...@faceh.com wrote:
      >>
      This cannot be a simple redirect
      >
      When configured specifically, you can make a page media.php which is
      also used whenhttp://www.domain.com/media.php/CLIENT_DIR/CLIENT_FILES
      is accessed. You can then parse the URL from the $_SERVER array.
      Anybody knows how this is called or configured?
      >
      Of course, you can use rewriting to get rid of the .php, so that you
      rewrite
      media/bla to media.php/bla
      >
      Now that I think of it, you can also rewrite
      media/bla to media.php?reque st=bla
      So that you can just get the request out of $_GET. However, this gives
      problems with some characters in filenames such as &.
      I can parse the $_SERVER['REQUEST_URI'] as you suggested to get to the
      desired file, however the issue with that is how to return image
      files, or pdf files, or .doc files, etc. as that file type. ie. if it
      links to a .jpg file, return a .jpg file. The only way I can think to
      do it is redirect to that file, which is not what I want. I think it
      is something to do with setting the file type in the php header, but
      not sure.

      Comment

      • Jeff

        #4
        Re: .htaccess style rewrite with php

        Joe wrote:
        On Aug 5, 11:21 am, Sjoerd <sjoer...@gmail .comwrote:
        >On Aug 5, 11:09 am, Joe <j...@faceh.com wrote:
        >>
        >>http://www.domain.com/media/CLIENT_DIR/CLIENT_FILES
        >>This cannot be a simple redirect
        >When configured specifically, you can make a page media.php which is
        >also used whenhttp://www.domain.com/media.php/CLIENT_DIR/CLIENT_FILES
        >is accessed. You can then parse the URL from the $_SERVER array.
        >Anybody knows how this is called or configured?
        >>
        >Of course, you can use rewriting to get rid of the .php, so that you
        >rewrite
        >media/bla to media.php/bla
        >>
        >Now that I think of it, you can also rewrite
        >media/bla to media.php?reque st=bla
        >So that you can just get the request out of $_GET. However, this gives
        >problems with some characters in filenames such as &.
        >
        I can parse the $_SERVER['REQUEST_URI'] as you suggested to get to the
        desired file, however the issue with that is how to return image
        files, or pdf files, or .doc files, etc. as that file type. ie. if it
        links to a .jpg file, return a .jpg file. The only way I can think to
        do it is redirect to that file, which is not what I want. I think it
        is something to do with setting the file type in the php header, but
        not sure.
        Perhaps what you want to do is read in the file from a protected
        location and print the header and then the file. Include the file type,
        disposition and name in the header.

        Jeff

        Comment

        Working...