Problems with RewriteMap

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 8
Joined: 08 Apr 2012, 18:14

Problems with RewriteMap

08 Apr 2012, 18:26

Have researched and tested several examples in the forum, but so far not been successful.


My Current URL
http://www.mysite.com.br/guiadacidade/index.asp?Cod=1

I need her to be well
http://www.mysite.com.br/guiadacidade/paone_product

First attempt - My. Htaccess is

Code: Select all
RewriteEngine on
RewriteMap mapfile txt:mapfile.txt
RewriteMap lower int:tolower
RewriteCond %{REQUEST_URI} ^/([^/]+)/([^/.]+)/$ [NC]
RewriteCond ${mapfile:${lower:%2}|NOT_FOUND} !NOT_FOUND
RewriteRule .? /guiadacidade/index.asp?cod=${mapfile:${lower:%2}} [NC,L]


2 - try, is not writing the log and I've given permission to the folder.
Code: Select all
RewriteEngine on
LogLevel debug
RewriteLog e:/vhosts/mysite.com.br/httpdocs/test/rewrite.log
RewriteLogLevel 9
RewriteRule  ^/via/?([a-zA-Z0-9_-]+)?(.html)?$ /via-de-contas-bm.asp[I,L]
RewriteBase /
RewriteMap mapfile txt:mapfile.txt
RewriteRule ^guiadacidade/([^?/]+)\.asp /index.asp?Cod=${mapfile:$1}


my mapfile.txt
Code: Select all
paone_product 1
another_product 2
our_super_tool 127
more_products 335


error message on the site
The system can not find the file specified.


It would be very grateful for those who give me a light

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

Re: Problems with RewriteMap

09 Apr 2012, 06:42

Hello,

I assume you need both... redirect from guiadacidade/index.asp?Cod=1 --> to --> guiadacidade/paone_product and at the same time also to load content from guiadacidade/index.asp?Cod=1 for this new page. Correct?

There's the following set of rules:

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

# 301-REDIRECT from old URL to a new one
RewriteCond %{QUERY_STRING} ^Cod=(\d+)$ [NC]
RewriteRule ^guiadacidade/index\.asp$ /guiadacidade/${mapfile:%1} [NC,R=301,L]

# rewrite to load content
RewriteCond ${revmapfile:$1|NOT_FOUND} !NOT_FOUND
RewriteRule ^guiadacidade/([^/]+)$ /guiadacidade/index.asp?Cod=${revmapfile:$1} [NC,L]


Where mapfile looks like:
Code: Select all
1 paone_product
2 another_product
127 our_super_tool
335 more_products


and revmapfile.txt looks like:
Code: Select all
paone_product 1
another_product 2
our_super_tool 127
more_products 335


Both are supposed to be located by the config file with the rules(in the same directory)

Regards
Andrew

User avatar
Posts: 8
Joined: 08 Apr 2012, 18:14

Re: Problems with RewriteMap

11 Apr 2012, 19:25

Hello

With the code you posted, my url looks like this
http://www.mysite.com.br/guiadacidade/?Cod=1

I need it looks like this
http://www.mysite.com.br/guiadacidade/paone_product

can you help me solve?

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

Re: Problems with RewriteMap

12 Apr 2012, 07:38

the only thing I'd fix is the following:

replace

Code: Select all
# 301-REDIRECT from old URL to a new one
RewriteCond %{QUERY_STRING} ^Cod=(\d+)$ [NC]
RewriteRule ^guiadacidade/index\.asp$ /guiadacidade/${mapfile:%1} [NC,R=301,L]

with

Code: Select all
# 301-REDIRECT from old URL to a new one
RewriteCond %{QUERY_STRING} ^Cod=(\d+)$ [NC]
RewriteRule ^guiadacidade/index\.asp$ /guiadacidade/${mapfile:%1}? [NC,R=301,L]


In case it doesn't change anything - check your mapfile.
You may also provide rewrite.log for the testing request. Logging issues described in FAQ

Regards
Andrew

User avatar
Posts: 8
Joined: 08 Apr 2012, 18:14

Re: Problems with RewriteMap

15 Apr 2012, 19:03


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

Re: Problems with RewriteMap

16 Apr 2012, 18:42

You probably haven't noticed the changes in my last post: it's '?' at the end of the redirect rule, it prevents from appending the querystring to your final URL.

Regards
Andrew

User avatar
Posts: 8
Joined: 08 Apr 2012, 18:14

Re: Problems with RewriteMap

30 Apr 2012, 23:22

Thank you Andrew
It worked perfectly.

But now another question came to me, sometimes I have several pages.

As an example below

My Current URL
http://www.mysite.com.br/guiadacidade/i ... 1&Pagina=2

I need her to be well
http://www.mysite.com.br/guiadacidade/paone_product/2

it is possible to adapt your previous solution?


and again thank you

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 11 guests