[Need Help] Rewrite RegEx

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 7
Joined: 30 Jan 2013, 00:02

[Need Help] Rewrite RegEx

30 Jan 2013, 00:18

So I have just recently installed ISAPI Rewrite 3
but I am having trouble understanding the syntax, if some on could help me that would be very helpful and save me some stress.

I have The page /facility_details.asp?facilityid=18279
which I want to display as like /facility/18279/some-name/

and I have a map file set up like.
some-name 18279
some-other-name 18280

httpd.conf
Code: Select all
RewriteBase /
RewriteMap mapfile txt:mapfile.txt
RewriteCond %{QUERY_STRING} ^facilityid=(\d+)$
RewriteMap lower int:tolower
RewriteRule ^facility_details/([^?/]+)\.asp$ facility\/{mapfile:${lower:$1}}



if someone could provide the httpd.conf or help me write it myself it would be much appreciated.

Thank-you
Thomas Albrighton

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

Re: [Need Help] Rewrite RegEx

30 Jan 2013, 01:15

Hm.... there're 2 rules that accomplish your task:

1 - the redirect from the ugly URL with querystring to a new one
2 - the rewrite rule that load the content for a new URL from an old source.

You have a mix of these two rules.

Lets try using:

Code: Select all
RewriteEngine on
RewriteBase /
RewriteMap mapfile txt:mapfile.txt
RewriteMap revmapfile txt:revmapfile.txt

RewriteCond %{QUERY_STRING} ^facilityid=(.+) [NC]
RewriteRule ^facility_details\.asp$ /facility/${mapfile:%1}? [NC,R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond ${revmapfile:$1|NOT_FOUND} !NOT_FOUND
RewriteRule ^facility/(.+)$ /facility_details.asp?${revmapfile:$1} [NC,L]


Where mapfile contains:
Code: Select all
234 some-thing
23234 another-name


and remapfile:
Code: Select all
some-thing 234
another-name 23234


Regards
Andrew

User avatar
Posts: 7
Joined: 30 Jan 2013, 00:02

Re: [Need Help] Rewrite RegEx

30 Jan 2013, 19:56

Thank-you
That helped a lot

Thomas Albrighton

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 0 guests