This forum has been moved here:
Helicon Tech Community Forum

ISAPI_Rewrite 3.0 (Forum Locked Forum Locked)
 Helicon Tech : ISAPI_Rewrite 3.0
Subject Topic: Map file with more than one parameter
Author
Message |
Anejo
Newbie


Joined: 23 September 2009
Location: Sweden
Posts: 11
Posted: 10 September 2011 at 7:48am

Hi, I'm trying to create some url-rewriting rules as
follows:

/mypage.asp?id=x&lng=yy

which I wish to convert to: /yy/some-file-name/

In the FAQ I found this solution, but it only takes one
parameter as I understand it, I need to have the /yy/ as
well.

Code:

.htaccess
RewriteEngine on

# Set a variable (�map�) to access map.txt from config
RewriteMap map txt:map.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

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

==================================
the mapfile, map.txt (example):
==================================
about-us          3
our-services          4
services          5
contact-us              6




In the database I have two fields realURL and seoURL

the realURL is the... real url (with all the parameters)

and the seoURL is (as for the samples above):

about-us.html
our-services.html
services.html
contact-us.html

And this works just fine, but I would like to skip the
file extension and have the url as the one I described
above: /lng/about-us/ (example)

Is this possible?

And also, I have other page templates except for
mypage.asp (with the same basic url-structure
/myotherpage.asp?id=x&lng=yy). I need to convert these as
well.

I have tried to find a solution by reading the
documentation, the FAQ and the forum, but I'm new to this
and can't really grasp how to implement the solution I
wish to implement.

If anybody could point me in the right direction - your
help would be much appreciated.




Back to Top
 
Guests
Guest


Joined: 01 October 2003
Online Status: Online
Posts: -160
Posted: 12 September 2011 at 6:02am

Hello,

In case you want your second parameter 'yy' to me passed directly, without using additional mapfile, please, try using:

Code:
RewriteMap map txt:map.txt
RewriteMap lower int:tolower

RewriteCond %{REQUEST_URI} ^/([^/]+)/([^/.]+)\.html$ [NC]
RewriteCond ${map:${lower:%2}|NOT_FOUND} !NOT_FOUND
RewriteRule .? /mypage.asp?apid=${map:${lower:%2}}&lng=%1 [NC,L]


In case you want to convert /myotherpage.asp?id=x&lng=yy to SEO type, try using:

Code:
RewriteMap revmap txt:revmap.txt
RewriteMap lower int:tolower

RewriteCond %{QUERY_STRING} ^id=([^&]+)&lng=([^&]+)$ [NC]
RewriteCond ${revmap:${lower:%1}|NOT_FOUND} !NOT_FOUND
RewriteRule .? /%2/${revmap:${lower:%1}} [NC,L]


Regards
Andrew



Back to Top
 
Anejo
Newbie


Joined: 23 September 2009
Location: Sweden
Posts: 11
Posted: 13 September 2011 at 6:05am

Hi Andrew and many thanks for your reply.

I tried your first example and it works to some extent. But not for both pages (i.e mypage.asp and otherpage.asp) - these are basically template-pages with different layout but working on the same db-table, and have the same url-structure. For swedish pages - these templates get info from tbl_pages_se and for english pages - the same template pages get their info from tbl_pages_en.

Ex. mypage.asp
============

a) mypage.asp?id=3&lng=se (for swedish content from tbl_pages_se)
b) mypage.asp?id=4&lng=se (same as above)

c) mypage.asp?id=3&lng=en (for english content - from tbl_pages_en)
d) mypage.asp?id=4&lng=en (same as above)

Ex. otherpage.asp
================

a) otherpage.asp?id=5&lng=se (swedish content from tbl_pages_se)
b) otherpage.asp?id=6&lng=se (same as above)

c) otherpage.asp?id=5&lng=en (english content from tbl_pages_en)
d) otherpage.asp?id=6&lng=en (same as above)

The database fields concerned (same in tbl_pages_se and tbl_pages_en)
========================================================

field: realURL
-------------
This is the url the system uses "internally" (i.e. my old "ugly" url)

ex. mypage.asp?id=3&lng=se

or (for english page)
ex. mypage.asp?id=3&lng=en

field: seoURL
-------------
This is the "public" url, a field I have added now trying to get ISAPI Rewrite to work with, and the URL I wish the user to see in the addressbar, on menus etc.

ex. /se/om-oss/ <-- this is how I want it to appear,

and for the english version it would appear like this:
ex. /en/about-us/

for now I have to have it stored as:
/sv/om-oss.html 

With your first example - this works, just fine!

But I really would like to get rid of the file extension (.html) as well, and just store it as /se/om-oss/

The main problem though is
... I cannot figure out how to get the rule for otherpage.asp to work as well, preferrably (if possible) using only one mapfile for both kind of pages (mypage.asp AND otherpage.asp and for both languages)

Here is the mapfile and code-sample below, I've added the otherpage.asp on a line in the .htaccess - only to try to illustrate what I wish to accomplish:

The mapfile
Code:

#the swedish pages (this commentline is not in the actual map.txt file)
om-oss           3
produkter        4
tjanster          5
kontakta-oss   6

# the english pages, the id:s might be the same
# but are fetched from the table tbl_pages_en
# (these four commented lines are not in the actual map.txt-file -
# just here for explanation purposes)

about-us    3
products    4
services     5
contact-us 6   

And the .htaccess (for obvious reasons the Rewrite-rule for otherpage.asp doesn't work - just there to illustrate that I need a rule for this as well, but don't know how to implement it.

Code:

RewriteEngine on

RewriteMap map txt:map.txt
RewriteMap lower int:tolower

RewriteCond %{REQUEST_URI} ^/([^/]+)/([^/.]+)\.html$ [NC]
RewriteCond ${map:${lower:%2}|NOT_FOUND} !NOT_FOUND
RewriteRule .? /mypage.asp?apid=${map:${lower:%2}}&lng=%1 [NC,L]
RewriteRule .? /otherpage.asp?apid=${map:${lower:%2}}&lng=%1 [NC,L] #<-- this rule doesn't work, I'm aware of that it needs a different solution.

The question is, how do I build the .htaccess syntax and the mafile(s) according to the info I've provided above?

Regards
Anette



Edited by Anejo - 13 September 2011 at 6:24am
Back to Top
 
Guests
Guest


Joined: 01 October 2003
Online Status: Online
Posts: -160
Posted: 14 September 2011 at 6:00am

According to your commnet "With your first example - this works, just fine!". To get rid of .html, please, try using:

Code:
RewriteMap map txt:map.txt
RewriteMap lower int:tolower

RewriteCond %{REQUEST_URI} ^/([^/]+)/([^/.]+)/?$ [NC]
RewriteCond ${map:${lower:%2}|NOT_FOUND} !NOT_FOUND
RewriteRule .? /mypage.asp?apid=${map:${lower:%2}}&lng=%1 [NC,L]



a) To use the the same conditions for otherpage.asp you'll need to write the in front of the rule once again.
b) You'll probably have to use 2 different (swedish and englsih) mapfiles to avoid problems with rewrites

Code:
RewriteEngine on

RewriteMap emap txt:emap.txt
RewriteMap smap txt:smap.txt
RewriteMap lower int:tolower

RewriteCond %{REQUEST_URI} ^/([^/]+)/([^/.]+)/$ [NC]
RewriteCond ${emap:${lower:%2}|NOT_FOUND} !NOT_FOUND
RewriteRule .? /mypage.asp?apid=${emap:${lower:%2}}&lng=%1 [NC,L]

RewriteCond %{REQUEST_URI} ^/([^/]+)/([^/.]+)/$ [NC]
RewriteCond ${smap:${lower:%2}|NOT_FOUND} !NOT_FOUND
RewriteRule .? /otherpage.asp?apid=${smap:${lower:%2}}&lng=%1 [NC,L]



Regards
Andrew
Back to Top
 
Anejo
Newbie


Joined: 23 September 2009
Location: Sweden
Posts: 11
Posted: 16 September 2011 at 10:59am

Hi Andrew this works perfectly.

Many thanks for your help!

Regards
Anette



Edited by Anejo - 16 September 2011 at 10:59am
Back to Top
 

Sorry, you can NOT post a reply.
This forum has been locked by a forum administrator.

Printable version Printable version