Adding parameter to mapfile rule

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 23
Joined: 24 Apr 2012, 13:14

Adding parameter to mapfile rule

15 May 2012, 06:01

Hi,

I need to add a parameter to these mapfile rules (to also accept a category id).

The url structure:
/cal.asp?id=5&lng=se
/cal.asp?id=6&lng=se

The "pretty url" (sample):
/se/title-of-the-page
/se/another-title

New url structure
/cal.asp?id=5&lng=se&cat=4 <-- added category parameter (it's going to fetch the category name)
/cal.asp?id=6&lng=se&cat=3

The new "pretty url" (sample)
/se/news/title-of-the-page <-- category news
/se/press/another-title <-- category press

The .htaccess
----------------
Code: Select all
RewriteEngine on
RewriteBase /

## CALENDAR MAPFILES
RewriteMap calendar_se txt:mfiles/calendar_se.txt

# Calendar
RewriteCond %{REQUEST_URI} ^/([^/]+)/([^/.]+)$ [NC]
RewriteCond ${calendar_se:${lower:%2}|NOT_FOUND} !NOT_FOUND
RewriteRule .? /cal.asp?id=${calendar_se:${lower:%2}}&lng=%1 [NC,L]



I've kind of got it working by modifying the rule as follows:
-------------------------------------------------------------------
RewriteCond %{REQUEST_URI} ^/([^/]+)/([^/.]+)/([^/.]+)$ [NC] <-- added
RewriteCond ${calendar_se:${lower:%2}|NOT_FOUND} !NOT_FOUND
RewriteRule .? /cal.asp?id=${calendar_se:${lower:%2}}&lng=%1&cat=%1 [NC,L] <-- added parameter

But it only accepts the "pretty url" if I put the "category" last, ex.
/se/title-of-the-page/news <--

instead of:
/se/news/title-of-the-page

The mapfile looks like this:
-------------------------------
Code: Select all
title-of-the page  5
another-title     6


Please note - I have two similar rules for the english and the german pages, but I guess that these could be modifed in the same way.
Kind Regards
/ Anejo

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: Adding parameter to mapfile rule

15 May 2012, 07:40

hello,

In the following rule:

Code: Select all
RewriteRule .? /cal.asp?id=${calendar_se:${lower:%2}}&lng=%1&cat=%1 [NC,L] <-- added parameter


The %1 and %2( also %3) are the values of the variables captured in (...). In this pattern /([^/]+)/([^/.]+)/([^/.]+) there're 3 values and you're using 2 similar %1 values.

Regards
Andrew

User avatar
Posts: 23
Joined: 24 Apr 2012, 13:14

Re: Adding parameter to mapfile rule

15 May 2012, 09:27

Hi Andrew,

I tried this but it didn't work

RewriteCond %{REQUEST_URI} ^/([^/]+)/([^/.]+)/([^/.]+)$ [NC]
RewriteCond ${calendar_se:${lower:%2}|NOT_FOUND} !NOT_FOUND
RewriteRule .? /cal.asp?id=${calendar_se:${lower:%2}}&lng=%1&cat=%3 [NC,L]


The querystring is:
----------------------
/cal.asp?id=5&lng=se&cat=4

And the "pretty url":
------------------------
/se/press/title-of-the-page

And the mapfile (calendar_se) is:
Code: Select all
title-of-the page  5
another-title     6


Kind Regards
/ Anette

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: Adding parameter to mapfile rule

15 May 2012, 09:50

According to your rule the resulting URL would be:

/cal.asp?id=VariableFrom_calendar_se&lng=se&cat=title-of-the page instead of /cal.asp?id=5&lng=se&cat=4

If you want to replace all values with the digits, than you need 2 or 3 mapfiles, not just passing the parameter.


Regards
Andrew

User avatar
Posts: 23
Joined: 24 Apr 2012, 13:14

Re: Adding parameter to mapfile rule

15 May 2012, 10:00

I'm not sure we're on the same page?

The underlying url is the querystring but the display to the user should be:

www.mysite.com/se/press/page-title

I use this url on all menus, internal links etc. as well

In the database I have these fields

real_url : /cal.asp?id=5&lng=se&cat=5
publicURL : /se/press/page-title <-- this is displayed on menus, internal links etc.

/ Anette

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: Adding parameter to mapfile rule

15 May 2012, 10:17

I do understand what happens. It's just instead of giving a right rule, I'm telling you what is not working so that you can fix it yourself.
I'm telling you that the rule needs to have both id and cat parameters drawn through the mapfiles

User avatar
Posts: 23
Joined: 24 Apr 2012, 13:14

Re: Adding parameter to mapfile rule

15 May 2012, 10:33

Hi Andrew,

OK so do you mean that the new parameter cat (category_id) needs to have an additional mapfile?

That means two mapfiles, one for storing the id and another for storing the category_id?

I can have 2 parameters for a single mapfile (ie lang and id) but not three?

And it's not possible to store "/" in a mapfile, because that would be sufficient actually

Like:

press/my-title 5
press/my-other-title 6
news/another-title 7

I really don't get this, I'm sorry ...
Is it possible to buy some time from you in order to solve this?
I have a ton of other tasks to solve on this system, and also have a deadline approaching so I'm a bit stressed out on this

Kind Regards
/ Anette

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: Adding parameter to mapfile rule

15 May 2012, 10:42

Correct, you need 2 of those as you're converting 2 different types of parameters:

Code: Select all
my-title 5
my-other-title 6
another-title 7


and
Code: Select all
news 1
category 2
category_other 3


Sure, you can buy Premium Support Plan and discuss everything online or ever let us do everything for you.

Regards
Andrew

User avatar
Posts: 23
Joined: 24 Apr 2012, 13:14

Re: Adding parameter to mapfile rule

15 May 2012, 10:59

Hi Andrew,

I've registered and payed for the premium supportplan. I'm posting a ticket in a moment.

Kind Regards
/ Anette

User avatar
Posts: 23
Joined: 24 Apr 2012, 13:14

Re: Adding parameter to mapfile rule

15 May 2012, 11:13

The Ticket id is #14592.

I've attached the .htaccess

User avatar
Posts: 23
Joined: 24 Apr 2012, 13:14

Re: Adding parameter to mapfile rule

15 May 2012, 11:21

Hellloooo!!!

No answer in the premium support and no answer here!

????

/ Anette

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: Adding parameter to mapfile rule

16 May 2012, 06:48

Anette, it's stated at the support page that we're located at +2GMT. There're also our working hours stated there.
Your premium ticket at helpdesk was answered hour-two ago, please, see helpdesk.

Regards
Andrew

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 5 guests