0
Options +FollowSymLinks

RewriteEngine On
RewriteMap name2id txt:/path/to/map.txt

RewriteRule ^/mods/([^/]+)\.html$ /mod.php?id=${name2id:$1|0} [QSA,L]

First time to make a URL rewriting with rewriteMap. I have a code above but it returns a 404 page if i run http://example.com/mysite/mods/abc.html in my browser. I've put the above code in my virtual host file in apache configuration, I read in some forums that rewriteMap only works if you have access in httpd.conf and virtual host. mod_rewrite is running on my windows machine because I was able to run some rule defined in my .htaccess file.

The map.txt contains

abc 123
def 456
ghi 789
Owen Blacker
  • 4,117
  • 2
  • 33
  • 70
christian
  • 153
  • 2
  • 13
  • Did you make sure mod_rewrite is running properly and Apache allows .htaccess files? – Gumbo Aug 03 '09 at 12:52
  • Yes, mod_rewrite is properly running and allow .htaccess file. I was able to run some rules defined in htaccess. – christian Aug 04 '09 at 00:57

2 Answers2

1

If you request /mysite/mods/…, your rule should rather be:

RewriteRule ^/mysite/mods/([^/]+)\.html$ /mod.php?id=${name2id:$1|0} [QSA,L]
Gumbo
  • 643,351
  • 109
  • 780
  • 844
  • but i declare my RewriteBase as /mysite. And even i add /mysite/mods/ still 404 is showing.. Is that okay if my rule is located in my htaccess file and the declaration of rewriteMap is in my virtual host? – christian Aug 03 '09 at 09:03
  • Have you tried starting the rule with *^mods* instead of *^/mods*? – Lars Haugseth Aug 03 '09 at 09:27
0

If you're using RewriteBase, try removing the initial slash in the rule:

RewriteRule ^mods/([^/]+)\.html$ /mod.php?id=${name2id:$1|0} [QSA,L]
Lars Haugseth
  • 14,721
  • 2
  • 45
  • 49
  • I got my code working, but when i run http://example.com/mysite/mods/abc.html I got 0 when i echoed the query string id, is that rigth? correct me if I'm wrong because i am expecting the equivalent of abc w/c is 123 will be displayed. – christian Aug 03 '09 at 10:01