views:

194

answers:

3

What is the difference in mod_rewrite between Apache 1.3(.37) and 2.2(.11)?

RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f

RewriteRule ^pages/edit(account|page)/([0-9]+)*$ ./index.php?p=edit$1&id=$2
RewriteRule ^pages/([\w'-]+)*$ ./index.php?p=$1

I wrote this and it "works on my machine" which is running Apache 2.2.11 but the production server that it needs to run on is Apache 1.3.37. I am really new to mod rewrite and just started learning regex this morning. where do i go from here?

update: I installed Apache 1.3.37 on my local machine. I am getting the error "Invalid command 'RewriteEngine', perhaps mis-spelled or defined by a module not included in the server configuration".

update 2: I fixed the problem i had with my local machine. now i am getting the same issue as on the production server.

A: 

I figured it out. Only the last rule was the problem. note the [^\w] instead of [\w'-].

RewriteRule ^pages/([^\w]+)*$ ./index.php?p=$1

This works with Apache 1.3.37 but no longer functions in Apache 2.2.11. if anyone knows a way to get this to work in both I really want to understand this instead of just making it work.

Samuel
A: 

Try replacing this:

[\w'-]

with this:

[-\w']

In some RegEx parsers, if you want - in a character set, it needs to be the first character, as it has a special meaning in character sets.

R. Bemrose
+1  A: 

Apache 1.x uses POSIX Extended Regular Expressions and those don’t understand shorthand character classes like \w. So try this:

RewriteRule ^pages/edit(account|page)/([0-9]+)$ ./index.php?p=edit$1&id=$2
RewriteRule ^pages/([A-Za-z0-9_'-]+)$ ./index.php?p=$1
Gumbo
This works on both versions. very nice!
Samuel