rewrite url products id and macrocat

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS

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

Re: rewrite url products id and macrocat

09 Jul 2012, 06:32

Hello,

You'll need mapfiles for that. See more here
Try using the following:

Code: Select all
RewriteEngine on
RewriteBase /
RewriteMap macro_mapfile txt:macro_mapfile.txt
RewriteMap pag_mapfile txt:pag_mapfile.txt

RewriteCond %{QUERY_STRING} ^idmacrocat=([^&]+)$ [NC]
RewriteCond ${macro_mapfile:%1|NOT_FOUND} !NOT_FOUND
Rewriterule ^pagine\.asp$ /${macro_mapfile:%1}.asp [NC,R=301,L]

RewriteCond %{QUERY_STRING} ^idmacrocat=([^&]+)&idpag=([^&]+)$ [NC]
RewriteCond ${macro_mapfile:%1|NOT_FOUND} !NOT_FOUND
RewriteCond ${pag_mapfile:%2|NOT_FOUND} !NOT_FOUND
Rewriterule ^pagine_detail.asp$  /${macro_mapfile:%1}/${pag_mapfile:%2}.asp [NC,R=301,L]


Tha mapfiles macro_mapfile.txt and pag_mapfile.txt are supposed to be located in the same folder as the rules. The content must look as following:

macro_mapfile.txt
Code: Select all
1    nameofmacrocat
454    nameofmacrocat234
34    nameofmacrocat4545


pag_mapfile.txt
Code: Select all
33     nameofpag
23     nameofpag1
11     nameofpag7


Regards
Andrew

User avatar
Posts: 12
Joined: 07 Jul 2012, 04:01

Re: rewrite url products id and macrocat

10 Jul 2012, 05:50


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

Re: rewrite url products id and macrocat

10 Jul 2012, 06:21

Well, that' vice versa:


Code: Select all
RewriteEngine on
RewriteBase /
RewriteMap rev_macro_mapfile txt:rev_macro_mapfile.txt
RewriteMap rev_pag_mapfile txt:rev_pag_mapfile.txt

RewriteCond ${rev_macro_mapfile:$1|NOT_FOUND} !NOT_FOUND
Rewriterule ^([^/]+)$ /pagine.asp?idmacrocat=${rev_macro_mapfile:$1} [NC,L]

RewriteCond ${rev_macro_mapfile:$1|NOT_FOUND} !NOT_FOUND
RewriteCond ${rev_pag_mapfile:$2|NOT_FOUND} !NOT_FOUND
Rewriterule ^([^/]+)/([^/]+)$  /pagine_detail.asp?idmacrocat=${rev_macro_mapfile:$1}&idpag=${rev_pag_mapfile:$2} [NC,L]



And your mapfiles are supposed to have their entries changed places.

Regards
Andrew

User avatar
Posts: 12
Joined: 07 Jul 2012, 04:01

Re: rewrite url products id and macrocat

10 Jul 2012, 07:04

HeliconAndrew wrote:And your mapfiles are supposed to have their entries changed places.


mean so

macro_mapfile.txt
Code: Select all
nameofmacrocat 1
nameofmacrocat234 454
nameofmacrocat454 534


pag_mapfile.txt
Code: Select all
nameofpag 33
nameofpag1 23
nameofpag7 11

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

Re: rewrite url products id and macrocat

10 Jul 2012, 07:54

Correct

User avatar
Posts: 12
Joined: 07 Jul 2012, 04:01

Re: rewrite url products id and macrocat

11 Jul 2012, 04:47

two questions

nameofpag must be the name of the page in its entirety with the extension
or it may be just the file name without extension?


what is the best way to manage the map file, since the data should I take them from the table of categories and products I have every time you change or add a new record recreate the file
should be one thing but in that split instant of time when a user is browsing the site can happen that there is some error due at that time the file is not updated / does not exist

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

Re: rewrite url products id and macrocat

11 Jul 2012, 06:02

Hello,

1) I've created the rule so that you show only the name of the file. It's more reliable by the means of regular expressions
2) Our customers use custom way of importing or exporting entries from mapfile, as it varies from the database and other parameters. So we can't suggest any particular way.

Regards
Andrew

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 21 guests