Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite regex from apache to apache2

apache2 will not compile "simple" regular expression

         

michaelsen

5:30 pm on Sep 26, 2008 (gmt 0)

10+ Year Member




Hello there,

With Apache I basically have this:

RewriteRule ^news/([0-9\]+)$ index.php?section=news&news_id=$1 [L]

Installing Apache2 I receive this error:

.htaccess: RewriteRule: cannot compile regular expression '^news/([0-9\\])$'

The only thing I got o work was the following:

RewriteRule ^news/(.+)$ index.php?section=news&news_id=$1 [L]

Is this correct?

Regards,

- Michaelsen

jdMorgan

5:37 pm on Sep 26, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your regex pattern was incorrect for either version. Try:

RewriteRule ^news/([0-9]+)$ index.php?section=news&news_id=$1 [L]

The "\" backslash in your pattern 'escaped' the "]" right square bracket character which followed it, leaving the [0-9] character-group specification un-closed.

If it was your intent to accept a backslash as part of the character group (in addition to characters 0 through 9), then the correct notation would be "[0-9\\]+"

Jim

michaelsen

7:50 pm on Sep 26, 2008 (gmt 0)

10+ Year Member




Hello again,

Nice to meet you Jim, I heard from you about mod_rewrite in other places.

For some reason it was working in my previous apache installation.

Thank you for the clarification.

Regards,

- Michaelsen

g1smd

8:55 pm on Sep 26, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



It worked by accident. The new version is less forgiving of that particular error.

jdMorgan

1:34 am on Sep 27, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It is likely that any URL composed of the characters 0-9, or ] would have been rewritten on the old server.

[added] Nice to meet you, too, Michaelsen... Sometimes I'm in too much of a hurry while posting. :( [added]

Jim

[edited by: jdMorgan at 1:36 am (utc) on Sep. 27, 2008]