views:

30

answers:

2
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
+1  A: 

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

RewriteRule ^/mysite/mods/([^/]+)\.html$ /mod.php?id=${name2id:$1|0} [QSA,L]
Gumbo
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
Have you tried starting the rule with *^mods* instead of *^/mods*?
Lars Haugseth
Yes I tried and still 404 is showing.
christian
A: 

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
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