mod_rewrite madness - Networking

This is a discussion on mod_rewrite madness - Networking ; I'm trying to enable the use of the + character in article titles in MediaWiki while retaining the use of clean URLS provided by mod_rewrite. For clean URLs, one needs to rewrite a URL of /wiki/(articlename) to /(path)/index.php?title=(articlename). The problem ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: mod_rewrite madness

  1. mod_rewrite madness

    I'm trying to enable the use of the + character in article titles in
    MediaWiki while retaining the use of clean URLS provided by mod_rewrite.

    For clean URLs, one needs to rewrite a URL of

    /wiki/(articlename)

    to

    /(path)/index.php?title=(articlename).

    The problem I run into is that the character + gets dropped from URLs.
    such that

    /wiki/C++

    ends up presenting a user with the article and URL

    /wiki/C

    Clearly an error. I've found that by navigating to

    /wiki/C%2B%2B

    I get an article title of C++. However, I have been unable to come up
    with a RewriteRule that would replace occurances of + in the URL with
    %2B. (C++ isn't the only article that would end up having + in the
    title; there's also Gtk+. I imagine there would eventually be more.)

    My current rewrite rules are thus:

    (start)
    RewriteEngine on
    RewriteRule ^$ /wiki/Main_Page [R]
    RewriteRule ^wiki/Special:Blog$ http://blog.rosettacode.org/
    [R=permanent,L]
    RewriteRule ^wiki/?(.*)$ /rosettacode/w/index.php?title=$1 [L,QSA]
    (end)

    (You can probably ignore the RewriteRule for the blog...It is included
    only for completeness.)

    I've tried the following rules: (one at a time, of course.)

    RewriteRule \+ %2B
    RewriteRule (.*)\+(.*) $1%2B$2
    RewriteRule (.*)\+(.*) $1\%2B$2

    and even

    RewriteRule (.*)\+(.*) $1$2

    All I get from my rules are recursive replacement behaviors or, failing
    that, HTTP 500 errors.

    One final note: The production server (run by someone else; I'm a
    gracious guest.) runs Apache 1.3. The test server (my laptop) runs
    Apache2. Getting Apache 1.3 running on my Ubuntu laptop (to match the
    server specs) would be difficult.

    Can someone tell me what I'm doing wrong, and perhaps give me a shove in
    the right direction?

    --
    Rosetta Code -- Building a Rosetta Stone for Programmers
    http://rosettacode.org

  2. Re: mod_rewrite madness

    "Michael Mol" schreef in bericht
    news:eqdmjo$5h4$1@aioe.org...
    > I'm trying to enable the use of the + character in article titles in
    > MediaWiki while retaining the use of clean URLS provided by mod_rewrite.
    > For clean URLs, one needs to rewrite a URL of
    > /wiki/(articlename) to /(path)/index.php?title=(articlename).
    >
    > The problem I run into is that the character + gets dropped from URLs.
    > such that /wiki/C++
    > ends up presenting a user with the article and URL
    > /wiki/C


    > Clearly an error. I've found that by navigating to
    > /wiki/C%2B%2B
    > I get an article title of C++.

    The + sign is an shorthand in URLencoding replacing %20 aka space.
    The literal + should be encoded %2B indeed

    Be aware the link you type into the navbar and a link found in a href='...'tag is NOT handled identical by the browser. will be
    encoded to C%2B%2B, while typing C++ is the navbar yourself is not encoded.
    Unfortunately Apache thinks the latter has two shorthand encoded trailing
    spaces to be decoded.

    > However, I have been unable to come up with a RewriteRule that would
    > replace occurances of + in the URL with %2B.

    The rule is fed the unencoded URL where the + is replaced by a space

    C# is your next stopper ...


    HansH




  3. Re: mod_rewrite madness

    "Michael Mol" schreef in bericht
    news:eqe32g$vau$1@aioe.org...
    > HansH wrote:
    >>> However, I have been unable to come up with a RewriteRule that would
    >>> replace occurances of + in the URL with %2B.

    >> The rule is fed the unencoded URL where the + is replaced by a space

    >
    > So a rule like
    >
    > RewriteRule \ \%2B
    > ought to work? I'll have to try that tomorrow.

    You may have to quote the slash and space(s)

    'Think you need to provide URLencode hrefs in your refering pages
    AND url-escape the value of title in
    RewriteRule ^wiki/?(.*)$ /.../index.php?title=$1 [L,QSA]
    like
    RewriteMap esc escape:
    RewriteRule ^wiki/?(.*)$ /.../index.php?title=${esc:$1} [L,QSA,NE]

    Note: RewriteMap not allowed in .htaccess ...

    >> C# is your next stopper ...

    > I've already given that thought. Intra-page links are a big part of my
    > site's organization; I can't just replace the # symbol. I'll have to
    > create an individual RewriteRule for C# and J#.

    Hint: %23 in href

    HansH



+ Reply to Thread