Having more than 1 ID in a map file

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 4
Joined: 24 Jan 2014, 09:29

Having more than 1 ID in a map file

24 Jan 2014, 09:35

HI All,

I have a scenario where I have a map file with the follwong structure:

product-name 1
product-name2 2
etc....

This looks up a product based on the matching ID. My products have different colours. So I would like to pass this colour ID (lets call it CID) as an extra value to my products page.

I was hopiing I could make a map file like this

product-name 1 23
product-name2 2 25
etc....

Where 23,25 are the CID's

I currently have it so that it works using this URL:

www.mydomain.com/product-name.html?CID=23
rewrites to:
www.mydomain.com/product-name.asp?ProductID=1 [QSA]

Which is fine - excep tit means my URL is now dirty again! How can i acheive passing 2 variables to my page from a full SEO friendly URL?

Many thanks,

Alex

User avatar
Posts: 402
Joined: 06 Mar 2012, 11:59

Re: Having more than 1 ID in a map file

24 Jan 2014, 10:09

Hello!

You can create two map files and use them in one rule. one would be "product-name ID" and another would be "colour colour-ID".

Also in general you can use database rewrite map features of Helicon Ape instead of ISAPI_Rewrite to build more comprehensive rewrites. Please check out these articles:
Introduction to database functionality of Helicon Ape
Keyword reach URLs in 5 minutes

User avatar
Posts: 4
Joined: 24 Jan 2014, 09:29

Re: Having more than 1 ID in a map file

24 Jan 2014, 11:22

Thanks Yaroslav.

So to implement this - the only line of htacess I will need to change (apart from adding a new line: 'RewriteMap map1 txt:map-colours.txt') would be something like this?

# Perform rewriting if the record was found in map-file)
RewriteRule .? /product-page.asp?ProductID=${map:${lower:%1}}&ColourID=${map1:${lower:%1}} [NC,L]

User avatar
Posts: 402
Joined: 06 Mar 2012, 11:59

Re: Having more than 1 ID in a map file

24 Jan 2014, 11:58

Your rule does not seem to be valid for two parameters. Please show your exact .htaccess, URL example and map file line example.

User avatar
Posts: 4
Joined: 24 Jan 2014, 09:29

Re: Having more than 1 ID in a map file

29 Jan 2014, 06:03

Hi Yaroslav,

Here is the htaccess code:

# Set a variable ("map") to access map-products.txt from config
RewriteMap map txt:map-products.txt

# Set a variable ("mapx") to access map-products.txt from config
RewriteMap mapx txt:map-colours.txt

# Use tolower function to convert string to lowercase
RewriteMap lower int:tolower

# Get requested file name
RewriteCond %{REQUEST_URI} ^/([^/.]+)\.html$ [NC]

# Seek file name in map-file
RewriteCond ${map:${lower:%1}|NOT_FOUND} !NOT_FOUND

# Seek file name in mapx-file
RewriteCond ${mapx:${lower:%1}|NOT_FOUND} !NOT_FOUND

# Perform rewriting if the record was found in map-file
RewriteRule .? /productsdetailx.asp?ProductID=${map:${lower:%1}}&ColorID=${mapx:${lower:%1}} [NC,L]


An example URL would be:

http://www.alldoorhandles.com/matt-nick ... plate.html

A sample line from 'map-products.txt':

Carlisle-Brass-EL60-EL61-EL62-Euroline-Wing-Door-Handle-on-Backplate 12202

A sample line from 'map-colours.txt'

matt-nickel 49

Am I correct in having the ID in 2 separate map files? or should they just be in the one?

Many thanks,

Alex

User avatar
Posts: 402
Joined: 06 Mar 2012, 11:59

Re: Having more than 1 ID in a map file

29 Jan 2014, 09:51

You will need to have some separator un URL that is not used in product names to separate colour name from product name, so you could match for two parameters in URL. Please choose how URL with product name and colour name would look like with the separator.

User avatar
Posts: 4
Joined: 24 Jan 2014, 09:29

Re: Having more than 1 ID in a map file

29 Jan 2014, 12:40

Hi Yaroslav,

I thought this URL was already doing that?:

www.alldoorhandles.com/matt-nickel/Carl ... plate.html

www.alldoorhandles.com/colour-name/product-name.html

Do you mean that it shoudl be like this:

www.alldoorhandles.com/colour_name/product-name.html

Regards,

Alex

User avatar
Posts: 402
Joined: 06 Mar 2012, 11:59

Re: Having more than 1 ID in a map file

29 Jan 2014, 13:31

Oh, sorry, I didn't noticed it. The rules would be something like:

Code: Select all
# Set a variable ("map") to access map-products.txt from config
RewriteMap map txt:map-products.txt

# Set a variable ("mapx") to access map-products.txt from config
RewriteMap mapx txt:map-colours.txt

# Use tolower function to convert string to lowercase
RewriteMap lower int:tolower

# Get requested file name
RewriteCond %{REQUEST_URI} ^/([^/.]+)\.html$ [NC]


# Match colour and product name:
RewriteCond ${mapx:${lower:$1}|NOT_FOUND} !NOT_FOUND
RewriteCond ${map:${lower:$2}|NOT_FOUND} !NOT_FOUND
RewriteRule ^([^/]+)/([^/.]+)\.html$  /productsdetailx.asp?ProductID=${map:${lower:$2}}&ColorID=${mapx:${lower:$1}} [NC,L]

# Match product name only (if no color):
RewriteCond ${map:${lower:$1}|NOT_FOUND} !NOT_FOUND
RewriteRule ^([^/.]+)\.html$  /productsdetailx.asp?ProductID=${map:${lower:$1}} [NC,L]


I have not tested these rules, so you may need to debug them a little, but I hope you've got the idea.

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 0 guests