SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Member
    Join Date
    Aug 2010
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    404 error when using # in url in rewrites

    Yes, I know that the # sign is reserved.

    These are used for named identifiers, ie xxx.html#gohere . These #'s, of course, are reserved, but is there a way to use them?

    I have tried to use %23 instead of the # sign in some url rewrites, but they all return 404 errors. I tried quotes also, but to no avail?

    Is there a way to use #'s in the url's anyway?


  2. #2
    SitePoint Member
    Join Date
    Aug 2010
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I guess there is NO way to use the rewrites to redirect with a named anchor in it?

    Evans Craig
    Last edited by dklynn; Aug 24, 2010 at 14:56. Reason: faux signature removed

  3. #3
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,671
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    eh,

    There is a good treatment of special characters (and Apache's parsing of the path and query string PRIOR to mod_rewrite) at https://issues.apache.org/bugzilla/s...i?id=32328#c12 which suggests that you CAN access {THE_REQUEST} to get the original, unescaped request string. It's UGLY (and will teach you to avoid such characters if at all possible) but it is available for you to access.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  4. #4
    Follow: @AlexDawsonUK silver trophybronze trophy AlexDawson's Avatar
    Join Date
    Feb 2009
    Location
    England, UK
    Posts
    8,111
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    Actually there is a pretty simple way to allow for the use of hash characters within a URL structure, all you need to-do is add a no-escape to your mod rewrites.

    Quote Originally Posted by http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html
    This flag keeps mod_rewrite from applying the usual URI escaping rules to the result of a rewrite. Ordinarily, special characters (such as '%', '$', ';', and so on) will be escaped into their hexcode equivalents ('%25', '%24', and '%3B', respectively); this flag prevents this from being done. This allows percent symbols to appear in the output
    As an example:

    Code:
    RewriteRule ^before.html$ /before.html#after [R,NE]
    PS: Patience is a virtue, we don't get paid to help people so don't expect immediate answers.

  5. #5
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,671
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    Alex,

    That's for the redirection. I believe that the OP was talking about preserving a page anchor. Thanks for that reminder, though (but don't forget the Last flag!).

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  6. #6
    Follow: @AlexDawsonUK silver trophybronze trophy AlexDawson's Avatar
    Join Date
    Feb 2009
    Location
    England, UK
    Posts
    8,111
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    Ah, I was under the assumption he was trying to invoke a redirect while ensuring the hash character wasn't filtered (I guess the OP will have to let us know!)

  7. #7
    SitePoint Member
    Join Date
    Aug 2010
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am trying to just use regular redirects with existing ones (we migrated to a new system that does not have the perl redirect script we were using prior)

    Here is the code I am trying to use:

    RewriteRule ^/Atlanta$ /pub/ed/ed_marketplace/in-person.html#cff [NC,R]

    evans

  8. #8
    SitePoint Member
    Join Date
    Aug 2010
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dklynn View Post
    Alex,

    That's for the redirection. I believe that the OP was talking about preserving a page anchor. Thanks for that reminder, though (but don't forget the Last flag!).

    Regards,

    DK
    What last flag?

  9. #9
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,671
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    eh,
    Quote Originally Posted by ehcraig View Post
    I am trying to just use regular redirects with existing ones (we migrated to a new system that does not have the perl redirect script we were using prior)

    Here is the code I am trying to use:

    RewriteRule ^/Atlanta$ /pub/ed/ed_marketplace/in-person.html#cff [NC,R]

    evans
    What else is in your .htaccess that could be impacting this?

    Alex is correct, though, as adding the page anchor needs the NoEscape (NE) flag.
    Quote Originally Posted by ehcraig View Post
    What last flag?
    The L flag that terminates a mod_rewrite (block) statement just like ; or } in JavaScript and PHP. PHP doesn't work without them, JavaScript is dicey but mod_rewrite will believe that the omission is intentional and will AND successive (block) statements until it receives the Last flag. In other words, learn to code correctly.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  10. #10
    SitePoint Member
    Join Date
    Aug 2010
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Wink

    Quote Originally Posted by dklynn View Post
    eh,

    What else is in your .htaccess that could be impacting this?

    Alex is correct, though, as adding the page anchor needs the NoEscape (NE) flag.

    The L flag that terminates a mod_rewrite (block) statement just like ; or } in JavaScript and PHP. PHP doesn't work without them, JavaScript is dicey but mod_rewrite will believe that the omission is intentional and will AND successive (block) statements until it receives the Last flag. In other words, learn to code correctly.

    Regards,

    DK
    Jeez dude!

    I am not doing this in the .htaccess file, I am using a redirects.conf file in the Apache content area, so I do not need to terminate each statement.

  11. #11
    SitePoint Member
    Join Date
    Aug 2010
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Alex.

    I am using the NoEscape (NE) flag & all is working correctly.

  12. #12
    Follow: @AlexDawsonUK silver trophybronze trophy AlexDawson's Avatar
    Join Date
    Feb 2009
    Location
    England, UK
    Posts
    8,111
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    Good to know, I had the same issue a while back so I had a feeling that it might have been what you were looking for


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
  •