Forum Moderators: phranque

Message Too Old, No Replies

urgent help please: RewriteMap

apache rewritemap function

         

Vvktse

4:57 pm on Aug 14, 2012 (gmt 0)

10+ Year Member



Hello

i am pretty new on the programming. i have encounter problem for the following. please kindly advise

i have website with

www.mysite.com/products.php?cid=3

which the last number 3, generated from backend database, ranged 1-3

i want to have it rewrite so that when people type:

www.mysite.com/nike will be directed to www.mysite.com/products.php?cid=1

www.mysite.com/reebok will be directed to www.mysite.com/products.php?cid=2

www.mysite.com/kswiss will be directed to www.mysite.com/products.php?cid=3

etc.....


i have the text file named category.txt under the root:
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>


however it does not work. can you please advise

phranque

1:21 am on Aug 16, 2012 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld, Vvktse!

what does it do?

g1smd

1:42 am on Aug 16, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



will be directed to

Do you want a redirect? This is where the URL shown in the browser changes as the browser makes a new request for the new URL.

Do you want a rewrite? This is where the request is rewritten to fetch the content from a different place inside the server compared to what the URL in the browser address bar shows. The URL in the browser address bar does not change.

RewriteRule can be configured to return an external redirect or perform an internal rewrite.

lucy24

5:27 am on Aug 16, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



which the last number 3, generated from backend database, ranged 1-3

Do you mean three? Literally three? One, two, three? 3? Where does the map come in? RewriteMaps are for when you have hundreds of Rewrites and you don't want to end up with an htaccess file that is thousands of lines long.

i want to have it rewrite so that when people type:

www.mysite.com/nike will be directed to www.mysite.com/products.php?cid=1

www.mysite.com/reebok will be directed to www.mysite.com/products.php?cid=2

www.mysite.com/kswiss will be directed to www.mysite.com/products.php?cid=3


:: business with crystal ball::

No, you don't. You want to have it so when they type or click

www.example.com/reebok

they will be shown content from

www.example.com/products.php?cid=2

And if they should happen to type

www.example.com/products.php?cid=2

they will first be [R=301] redirected to

www.example.com/reebok

before you show them the content of

www.example.com/products.php?cid=2