You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Brian Foley <br...@maths.tcd.ie> on 2004/08/18 20:59:33 UTC

[users@httpd] mod_rewrite and special characters

Hi All,

I posted this query to alt.configuration.apache a few days ago, but
got no response.  Apologies to those of you who are reading this for
the second time.  If my question is too simple, or not clear enough to
be answered, I would appreciate somebody pointing that out to me :-)



From: alt.configuration.apache:

Hello,

I have the following rule in my .htaccess file:
RewriteRule ^results/championship/(.*)/
/results/index.pl?championship=$1

Designed to rewrite URLs of the following form:
http://www.domain.com/results/championship/ABC/
into:
http://www.domain.com/results/index.pl?championship=ABC

This works as expected as long as the string ABC does not contain any
special characters.  One string I would like to use is "T&F".  The
URL:
http://www.domain.com/results/championship/T%26F/
gets transformed into:
http://www.domain.com/results/index.pl?championship=T&F
instead of the desired:
http://www.domain.com/results/index.pl?championship=T%26F

My problem being that the index.pl script thinks that "championship"
is "T" instead of the desired "T&F".

Is there a way to ask apache NOT to transform any url-encoded strings
it encounters while rewriting the URL?

I have come across rules like:
RewriteMap esc int:escape
which sound like they should work, while browsing the manual and
searching google.  Unfortunately, RewriteMap has to be in the
httpd.conf file and I only have access to .htaccess.

Anybody have a solution that will work in my .htaccess file?

Can somebody confirm whether RewriteMap is likely to work?  If I
managed to convince my hosting provider to insert a RewriteMap rule
into the global httpd.conf file, would I be able to use "esc" in my
.htaccess file, or would both RewriteMap and RewriteRule statements
need to be in the same file?

Thanks,

Brian.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] mod_rewrite and special characters

Posted by Brian Foley <br...@maths.tcd.ie>.
* Joshua Slive [jslive@gmail.com] on [18-08-04] wrote:
> Does this happen for all "special characters", or just for &.  The
> amphersand is a "special"-"special" character, because it needs to be
> escaped in some circumstances but not others.  If it is just that
> particular character that is a problem, you could use something like

Hello Joshua,

> RewriteRule ^results/championship/(.*)(%26F)?(.*)/
> /results/index.pl?championship=$1%26F$2 [NE]

That got me on the right route.  I am now using two lines:

RewriteRule ^results/championship/(.*)&(.*)/
/results/index.pl?championship=$1\%26$2

RewriteRule ^results/championship/(.*)/
/results/index.pl?championship=$1

Notice the escaping of the % in the first rule...

Can anybody explain to me HOW this works?  Note the bare & in the
first part of the rule.  It seems that %-hex characters are converted
to their underlying character before the URL gets to the RewriteRule.
Is that correct?  I also dont understand why the rule works with and
without [NE]???

Still confused, but at least I have a solution now.  I dont like the
idea of duplicating all of my RewriteRules in my .htaccess, though...

Thanks,

Brian.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] mod_rewrite and special characters

Posted by Joshua Slive <js...@gmail.com>.
On Wed, 18 Aug 2004 19:59:33 +0100, Brian Foley <br...@maths.tcd.ie> wrote:

> I have the following rule in my .htaccess file:
> RewriteRule ^results/championship/(.*)/
> /results/index.pl?championship=$1


> This works as expected as long as the string ABC does not contain any
> special characters.  One string I would like to use is "T&F".  The
> URL:
> http://www.domain.com/results/championship/T%26F/
> gets transformed into:
> http://www.domain.com/results/index.pl?championship=T&F
> instead of the desired:
> http://www.domain.com/results/index.pl?championship=T%26F

Does this happen for all "special characters", or just for &.  The
amphersand is a "special"-"special" character, because it needs to be
escaped in some circumstances but not others.  If it is just that
particular character that is a problem, you could use something like

RewriteRule ^results/championship/(.*)(%26F)?(.*)/
/results/index.pl?championship=$1%26F$2 [NE]

The escaping rules are quite complicated, and I haven't played with
them much, so you might need to make adjustments to that.  The
RewriteLog could help alot, but you might not have access to that.

Joshua.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org