0

that's my mod_rewrite rules for lighttpd:

url.rewrite-once = (
    "^/label/([-'\./\+a-z0-9A-Z]+)/$" => "/index.php?page=label&label=$1",
    "^/riddim/([-'\./\+a-z0-9A-Z]+)/$" => "/index.php?page=riddim&riddim=$1",
    "^/([a-z]+)$" => "/index.php?page=$1",
    "^/(!?pma)([a-z]+)/?$" => "/index.php?page=$1"
)

The problem is that the character ' (39 .d) is somehow breaking the link and I get a 404 error.

/riddim/Some+Thing+Here+9.38/ --> works, page is shown
/riddim/Someone's+Stuff+Here/ --> fails, page not found 404 error

I have already tried using "^/riddim/(.+)/$" and it works, so I guess the ' is breaking the link/mod_rewrite. I even tried escaping the char (using: \'), even though I never heard of a regex engine using ' as some special character, but that failed, too.

The lighttpd is running on the webserver, on my computer I'm using XAMPP with apache, I set the same regex/rules there and it works just fine:

RewriteEngine on
RewriteRule ^/label/([-'\./\+a-z0-9A-Z]+)/$ /index.php?page=label&label=$1
RewriteRule ^/riddim/([-'\./\+a-z0-9A-Z]+)/$ /index.php?page=riddim&riddim=$1
RewriteRule ^/([a-z]+)$ /index.php?page=$1

What am I doing wrong?

phew
  • 808
  • 1
  • 15
  • 34
  • What _does_ it do? "works" vs "fails" is a bit loose. How does it fail? – FrankieTheKneeMan Sep 12 '12 at 20:06
  • well, if the link contains a ' char, the regex fails and therefore it sends you to 404 error instead of the page. Here's the example: [WORKING](http://riddimbase.net/riddim/Do+You+Love/) [FAILING](http://riddimbase.net/riddim/Don't+Let+Them/) -- its definately a regex problem as replacing the regex by ^/riddim/(.+)/$ makes it work for both links, though I don't see why the regex wouldn't match – phew Sep 12 '12 at 21:20

1 Answers1

1

The problem was that ' got URL-encoded to %27 even though my browser has still shown it as ', that's why the regex did not match because the character group did not contain % yet.

The new regex looks like

 "^/riddim/([-'\./\+a-z\%0-9A-Z]+)/$"

and is working like a charm!

j0k
  • 22,600
  • 28
  • 79
  • 90
phew
  • 808
  • 1
  • 15
  • 34
  • I'd accept it but I can't for 48 hours. Still 7 hours left until I can accept my own answer. – phew Sep 14 '12 at 12:16