I am pretty new to programming, and have encountered the following problem. Please kindly advise me.
I have a website with a URL like www.mysite.com/products.php?cid=3
where the value of the parameter cid
(3 here) is generated from a backend database, and can be a number from 1 to 3.
I would like Apache to rewrite the URL, so that:
www.mysite.com/nike
will redirect to www.mysite.com/products.php?cid=1
www.mysite.com/reebok
will redirect to www.mysite.com/products.php?cid=2
www.mysite.com/kswiss
will redirect to www.mysite.com/products.php?cid=3
etc...
I have a text file named category.txt under the root directory with the following content:
nike 1
reebok 2
kwiss 3
and .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
rewritemap categorymap txt:/image/categorymap.txt
RewriteRule ^(.*) /products.php?cid=${categorymap:$1|NOTFOUND} [PT]
</IfModule>
This, however does not work, please advise me,
The
RewriteMap
directive can only be used in either server or vhost config. You'll need to define it there. If you don't have access to either server or vhost config, then you'll just need to enumerate all of those into individual rewrite directives like: