大网数据广告活动
网站运营与故障问答

Htaccess Using RewriteMap with a text file

· 52CE 我爱测

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. generated map - map.txt title id color-1* 1 colo…

问题原文

原帖链接 · Mantykora 7 · CC BY-SA 4.0

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.

已采纳解答

原帖链接 · MrWhite · CC BY-SA 4.0

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)

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2020-11-03)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。