PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > alt.apache.configuration > mod_rewrite madness
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
alt.apache.configuration Apache web server configuration issues.

mod_rewrite madness

Réponse
 
LinkBack Outils de la discussion
Vieux 07/02/2007, 23h16   #1
Michael Mol
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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
  Réponse avec citation
Vieux 08/02/2007, 02h21   #2
HansH
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: mod_rewrite madness

"Michael Mol" <mikemol@gmail.com> 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 <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


  Réponse avec citation
Vieux 08/02/2007, 02h48   #3
Michael Mol
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: mod_rewrite madness

HansH wrote:
> "Michael Mol" <mikemol@gmail.com> schreef in bericht
> news:eqdmjo$5h4$1@aioe.org...
>> 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
  Réponse avec citation
Vieux 08/02/2007, 07h55   #4
HansH
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: mod_rewrite madness

"Michael Mol" <mikemol@gmail.com> 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


  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 22h17.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,13239 seconds with 12 queries