Networking Forums

Networking Forums > Computer Networking > Linux Networking > mod_rewrite madness

Reply
Thread Tools Display Modes

mod_rewrite madness

 
 
Michael Mol
Guest
Posts: n/a

 
      02-07-2007, 10:16 PM
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
 
Reply With Quote
 
 
 
 
HansH
Guest
Posts: n/a

 
      02-08-2007, 01:21 AM
"Michael Mol" <(E-Mail Removed)> schreef in bericht
news:eqdmjo$5h4$(E-Mail Removed)...
> 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 <a
href='...'tag is NOT handled identical by the browser. <a href=C++> 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


 
Reply With Quote
 
Michael Mol
Guest
Posts: n/a

 
      02-08-2007, 01:48 AM
HansH wrote:
> "Michael Mol" <(E-Mail Removed)> schreef in bericht
> news:eqdmjo$5h4$(E-Mail Removed)...
>> 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 <a
> href='...'tag is NOT handled identical by the browser. <a href=C++> 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.


I'll have to pay attention to that. Thanks.

>
>> 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.

>
> 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#.

--
Rosetta Code -- Building a Rosetta Stone for Programmers
http://rosettacode.org
 
Reply With Quote
 
HansH
Guest
Posts: n/a

 
      02-08-2007, 06:55 AM
"Michael Mol" <(E-Mail Removed)> schreef in bericht
news:eqe32g$vau$(E-Mail Removed)...
> 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 With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Firewall madness? Mickel Windows Networking 12 05-19-2010 12:10 PM
Wireless Network Madness DocDee Wireless Networks 1 03-02-2007 03:17 PM
Apache mod_rewrite mod_proxy_html Henning Eiben Linux Networking 2 02-08-2007 02:45 PM
mod_rewrite help needed google@w98.us Linux Networking 1 02-10-2005 07:55 AM
mod_rewrite: replace all occurance of a character jason.yfho@gmail.com Linux Networking 2 01-06-2005 03:34 PM



1 2 3 4 5 6 7 8 9 10 11