Argh, please help, 301 doesnt work because directory name has spaces?

Discussion in 'Apache' started by thudufushi, Mar 8, 2007.

  1. #1
    Guys,

    Im trying to redirect from:

    w ww.domain.com/data%20sheets/sheet_1.pdf

    to

    w ww.domain.com/sheet_1.htm

    But it wont work. I am thinking its because the pdf file i am trying to redirect from is in a folder whose name has spaces, on the server it just appears as data sheets but in the web browser when you view the file it shows the address line as http://www.domain.com/data sheets/sheet_1.pdf

    What should I put in my rewrite to get this to work, its driving me mad.

    Thanks,
     
    thudufushi, Mar 8, 2007 IP
  2. gw1500se

    gw1500se Member

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #2
    The %20 is standard URL notation for a space. The percent (%) is a delimiter indicating the next two characters represent the decimal value of an ascii character. Your rewrite should include that anywhere a space appears in the rule. The purpose is to avoid conflicts with characters that are meaningful to browsers. When a space is encountered in a URL that indicates the end of the URL. In order to prevent the browser from stopping at a space you must "fool" it into continuing. That is done buy changing the space to %20 which the server knows how to interpret. Any ascii character can be included in a URL in this manner.
     
    gw1500se, Mar 10, 2007 IP
  3. thudufushi

    thudufushi Well-Known Member

    Messages:
    1,145
    Likes Received:
    75
    Best Answers:
    0
    Trophy Points:
    155
    #3
    Hi, Thanks for the full explanation. I understand that the %20 is the notation for a space, but my rewrite rule above will just not work and the pdf file keeps loading instead of redirecting to the .htm file. I just thought it wasnt working (and still do) because of the folder name which has a space in it and this was cocking up my rewrite rule. How should I write this rule so it will work. I have tried a 301 from a another htm to another htm not inside this folder and it works fine
    Thanks in anticipation
    Steve
     
    thudufushi, Mar 12, 2007 IP
  4. gw1500se

    gw1500se Member

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #4
    Sorry, I guess I misread what you are trying to do. I don't think I still understand. If I take what you are saying literally, it sounds like you are trying to do a redirect from a pdf file. That is not possible since it is the pdf reader that is displaying the file not a browser. I am not aware of a pdf reader that understands html meta-tags, which is what is needed to tell a browser to do a redirect. I didn't really think that is what you wanted, thus my misunderstanding. Perhaps you could expand and clarify a little more.

    P.S. Can I also assume the space in the "w ww" is a typo? That won't work in any case.
     
    gw1500se, Mar 12, 2007 IP
  5. thudufushi

    thudufushi Well-Known Member

    Messages:
    1,145
    Likes Received:
    75
    Best Answers:
    0
    Trophy Points:
    155
    #5
    Yes, I want a collection of PDF files that are in googles index to redirect to their newly created .htm file. So you cannot redirect a pdf is what I seem to be learning?

    The space in the www was added to avoid auto link create by DP, as this then made it impossible to see the underscore
    Thank, appreciate your help.
    Steve
     
    thudufushi, Mar 12, 2007 IP
  6. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #6
    Post your current .htaccess code.
     
    Nintendo, Mar 13, 2007 IP
  7. thudufushi

    thudufushi Well-Known Member

    Messages:
    1,145
    Likes Received:
    75
    Best Answers:
    0
    Trophy Points:
    155
    #7
    All I have done is added the bottom 2 lines, to the existing htaccess file. The person above is saying you cant redirect a pdf!? I dont understand that because it wouldnt get that far, its a server side response to an address. Anyway, hopefully you can help by looking at the below.Thank you.

    # -FrontPage-

    IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*

    <Limit GET POST>
    order deny,allow
    deny from all
    allow from all
    </Limit>
    <Limit PUT DELETE>
    order deny,allow
    deny from all
    </Limit>
    AuthName xxxx.co.uk
    AuthUserFile /homepages/33/d112078959/htdocs/_vti_pvt/service.pwd
    AuthGroupFile /homepages/33/d112078959/htdocs/_vti_pvt/service.grp
    RewriteEngine on
    RewriteRule ^xxxx%20xxxx%20xxxx/xxxx_xxxx.pdf /xxxx_xxxx.htm [R=301,L]
     
    thudufushi, Mar 14, 2007 IP
  8. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #8
    RewriteRule ^xxxx\ xxxx\ xxxx/xxxx_xxxx\.pdf$ http://www.domain.com/xxxx_xxxx.htm [R=301,L]

    for one URL, or

    RewriteRule ^data\ sheets/([^.]+)\.pdf$ http://www.domain.com/$1.htm [R=301,L]

    for a whole directory, might do it.
     
    Nintendo, Mar 14, 2007 IP
  9. thudufushi

    thudufushi Well-Known Member

    Messages:
    1,145
    Likes Received:
    75
    Best Answers:
    0
    Trophy Points:
    155
    #9
    Hi Nintendo, Thanks but that doesnt work. :(
     
    thudufushi, Mar 15, 2007 IP
  10. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #10
    Make a post at webmasterworld.com/forum92/ *gags* Da mod_rewrite King is there.
     
    Nintendo, Mar 15, 2007 IP