SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    Always learning viveknarula's Avatar
    Join Date
    Mar 2006
    Location
    INDIA
    Posts
    418
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Mode rewrite special characters allowed ?

    Hi,

    I have an special characters in URL. I am using HTACCESS to mod rewrite of URLs such as http://www.mysite.com/username to http://www.mysite.com/user=username

    I am using this CODE in HTACCESS

    Code:
    Options +Indexes
    RewriteEngine on
    RewriteBase /
    RewriteCond %{HTTP_HOST} !^www\.mysite\.com$ [NC]
    RewriteRule .? http://www.mysite.com%{REQUEST_URI} [R=301,L]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([-_a-zA-Z0-9\.\\\]+)/$ myfile.php?user=$1
    It was working fine untill i found some other characters such as "[" and "]" and ":" in one of the URL. I tried to give access to them by putting these as \]\[\: in the above allowed symbols same as above symbols but it is not working and giving me 404 not found error on the server. Also these symbols converts into their correspondence html entities such as %5d etc..

    Please help me to resolve this issue.

    Thanks

  2. #2
    SitePoint Enthusiast elecktricity's Avatar
    Join Date
    Oct 2005
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Add the % to your expression which is what it needs, when you view the string itll convert it back.

  3. #3
    Always learning viveknarula's Avatar
    Join Date
    Mar 2006
    Location
    INDIA
    Posts
    418
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by elecktricity View Post
    Add the % to your expression which is what it needs, when you view the string itll convert it back.
    Can you please clarify more about this. Where should i put this ? In which expression should i put this ?

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

    There are characters which are NOT ALLOWED in URIs (Uniform Resource Identifiers (URI): Generic Syntax) and ? is highly restricted as it is used in a URL specifically to separate the URI from the trailing query string. In other words, find a substitute character as you simply cannot use ?.

    Further, within a character range, you do not have to escape the dot character. Likely, that applies to your accented characters (ö, ü and &#253, too.

    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

  5. #5
    Always learning viveknarula's Avatar
    Join Date
    Mar 2006
    Location
    INDIA
    Posts
    418
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dklynn View Post
    viv,

    There are characters which are NOT ALLOWED in URIs (Uniform Resource Identifiers (URI): Generic Syntax) and ? is highly restricted as it is used in a URL specifically to separate the URI from the trailing query string. In other words, find a substitute character as you simply cannot use ?.

    Further, within a character range, you do not have to escape the dot character. Likely, that applies to your accented characters (, and ), too.

    Regards,

    DK
    DK,

    I apologies as i think i was not clear in my post. I am NOT asking for "?" However, i am looking for "[" and "]" and ":" to allow in the URL.

    Thanks

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

    Did you read the article at the link I provided? I believe that both are reserved characters, too, therefore, you cannot have them in a URI (without being encoded). Once you encode them, they'll get matched by . and repeated (encoded, of course) for the redirection.

    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

  7. #7
    SitePoint Addict
    Join Date
    Dec 2005
    Posts
    276
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The latest spec is RFC 3985. Section 2.2 lists the reserved characters.

    The rule you want is something like this:
    Code:
    RewriteRule ^([.-_a-zA-Z0-9%]+)/$ myfile.php?user=$1
    "Never imagine yourself not to be otherwise than what
    it might appear to others that what you were or might
    have been was not otherwise than what you had been
    would have appeared to them to be otherwise."

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

    Apache translates the encoded characters so, if they are not reserved (apparently, [ & ] are), you should use them in your regex, otherwise, find an acceptable character.

    Elda,

    Thanks for the (draft) update (which clearly shows [ and ] as reserved characters - along with the note that:
    If data for a URI component would conflict with a reserved
    character's purpose as a delimiter, then the conflicting data must be
    percent-encoded before the URI is formed.
    Regarsd,

    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

  9. #9
    Always learning viveknarula's Avatar
    Join Date
    Mar 2006
    Location
    INDIA
    Posts
    418
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy

    Sorry Guys, i was away for few days........,

    DK and Elda, i have gone through the articles. I am still a bit confuse about those reseverd words can you please tell me in somewhat simple words.

    Thanks for all of your efforts and information.



    Quote Originally Posted by dklynn View Post
    viv,

    Apache translates the encoded characters so, if they are not reserved (apparently, [ & ] are), you should use them in your regex, otherwise, find an acceptable character.

    Elda,

    Thanks for the (draft) update (which clearly shows [ and ] as reserved characters - along with the note that:
    If data for a URI component would conflict with a reserved
    character's purpose as a delimiter, then the conflicting data must be
    percent-encoded before the URI is formed.
    Regarsd,

    DK

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

    Very simply, you cannot use [ or ] in a URL.

    As for your accented characters, just include them in the character range as if they were merely another character (do NOT attempt to encode them as Apache decodes before attempting to match).

    Regards,

    DK

    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


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
  •