301 Redirect Static URL to Dynamic URL

Discussion in 'Apache' started by muiomuio, Jun 4, 2009.

  1. #1
    I'm having a problem and so far haven't found a solution for this.

    the old url is something like this: www.somewebsite.com/pdf/123.pdf

    on the new website the CMS adds a number, generated automatically to the end of the pdf file so instead of 123.pdf I end up with 123_09289.pdf. I talked to the programing team that developed the CMS but at this point they cannot remove the portion of code that adds the number.

    So i'm looking for a way to 301 redirect www.somewebsite.com/pdf/123.pdf to www.somewebsite.com/someurl/123_8796876.pdf

    the number changes everytime you upload a file. It this possible with htaccess? If not, what is my best solution?
     
    muiomuio, Jun 4, 2009 IP
  2. pr0t0n

    pr0t0n Well-Known Member

    Messages:
    243
    Likes Received:
    10
    Best Answers:
    10
    Trophy Points:
    128
    #2
    You will probably have to manually add a line for each such file in your .htaccess file for redirect/rewrite rule. Since those numbers are random probably... and can not be predicted... you will have to add a line for each such file, where you are telling your apache server what is the exact name of uploaded file.

    The other option would be to ask your programmers to make another script for you... where you will configure in that script which virtual file name fetches which real file... and then you rewrite all download url's to that download script... though this may get a bit complicated. For example:

    1. You configure your download script for 123.pdf to fetch 123_blahblah.pdf
    2. You already have a line in your .htaccess where all download attempts are rewritten to that download script... yourdomain.com/some/download/folder/123.pdf is getting rewritten to yoursite.com/download.php?file=123.pdf (for example)
    3. Your download script reads that "file" variable, and then streams a real file based on the filename (that you have previously configured in your download script that 123.pdf is supposed to show 123_blahblah.pdf)

    It may sound a bit complicated.. but it isn't too much. All you need is that download script, and one mod_rewrite line in your .htaccess

    Just a suggestion...
     
    pr0t0n, Jun 5, 2009 IP