I can't use link with * Example - http://localhost/photo_gallery/public/show_c.html/color-1* The requested URL was not found on this server. The others work's color-3, wood, etc.

  1. generated map - map.txt

    title   id
    color-1* 1
    color-1** 2
    color-3 3
    wood 4
    color777 5
    color-test 6
  2. htaccess

    RewriteRule ^show_c.html/([-\w]+)$ show_c.php?cat=${catcolors:$1} [L]
  3. httpd.conf

    RewriteMap catcolors "txt:C:\wamp\www\photo_gallery\public\maps\map.txt"

My question. Why the link with * cannot be used.

1 Answer 1

RewriteRule ^show_c.html/([-\w]+)$ show_c.php?cat=${catcolors:$1} [L]

The regex [-\w]+ does not match *, so the pattern never matches the requested URL-path and the value is never looked up in the rewrite map.

Try the following instead:

RewriteRule ^show_c\.html/([-*\w]+)$ show_c.php?cat=${catcolors:$1} [L]

The literal * does not need to be backslash escaped in the regex character class as it carries no special meaning here. (But remember to backslash escape literal dots in other parts of the regex.)

Specifically, the regex [-*\w]+ matches 1 or more of the following:
- (hyphen), * (asterisk), a-z, A-Z, 0-9 and _ (underscore)

  • I knew I had to add somewhere *. Thank you very much again. Nov 3, 2020 at 14:58
  • You're welcome. I've just updated my answer with what it does actually match.
    – MrWhite
    Nov 3, 2020 at 14:59
  • 1
    live http://mantykora.cleoni.com:8080/photo_gallery/public/show_c.html/color-1* with this RewriteRule ^show_c\.html/([-*\w]+)$ show_c.php?cat=${catcolors:$1} [L] Nov 3, 2020 at 15:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.