1

I have the following URL:

http://example.com/gallery/thumb.php?h=400&w=300&a=c&src=Img_0.jpg

Which I'm trying to use mod_rewrite to make "pretty".

The desired URL is:

http://example.com/h/400/w/300/a/c/src/Img_0.jpg

And my mod_rewrite is:

RewriteRule ^h/(*)/w/(*)/a/(*)/src/(*)$ /gallery/thumb.php?h=$1&w=$2&a=$3&src=$4 [L]

But I'm getting a 500 Internal Server Error error which tells me I've written this rule wrong.

What did I write wrong about it?

EDIT: Not a duplicate. My question is pertaining to a particular code that I tried to write myself and did not manage to write a working code.

1 Answers1

3

This is not valid in your regular expression: (*).

* denotes a repetition of the previous character. Since you don't have any character in the group there is nothing to repeat.

If you change (*) to (.*) the expression becomes valid. . denotes "every character", so you might want to restrict that a little further.

An expression for your example could be:

RewriteRule ^h/(\d+)/w/(\d+)/a/([a-z]+)/src/(.+)$ /gallery/thumb.php?h=$1&w=$2&a=$3&src=$4 [L]

Where \d denotes a digit and [a-z] any character in this range. I also changed * to +, which matches on "1 or more characters", instead of "0 or more", which would be the *.

Gerald Schneider
  • 25,025
  • 8
  • 61
  • 90