showing 404 page on mapped page

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 1
Joined: 26 Oct 2012, 10:06

showing 404 page on mapped page

26 Oct 2012, 10:22

404Error.png
404Error.png (127.5 KiB) Viewed 3552 times
Hi,

we are using map file to dynamically show our product display. if user type a wrong url, which is not included in map file, we want the page to be redirected to 404. Currently it is showing an error "Input string was not in a correct format.". you can check the attached image.

our product map file is as follows.
ProductA 33
ProductB 32
ProductC 31
ProductD 30
ProductE 29

We are using following rewrite rules in our .htaccess file.

RewriteEngine on
RewriteMap ProductMapFile txt:MapFiles/ProductMapFile.txt [NC]
RewriteRule ^product/([^./]+)([/]*)$ displayproduct.aspx?pid=${ProductMapFile:$1} [NC,L]



It will be very helpful if somebody can provide a point to overcome this bug.

Regards,
Joby

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

Re: showing 404 page on mapped page

27 Oct 2012, 00:02

Hey,

I think we can solve it:

Code: Select all
RewriteEngine on
RewriteMap ProductMapFile txt:MapFiles/ProductMapFile.txt [NC]

# if the entry is not in the mapfile, ignore the rule
RewriteCond ${mapfile:$1|NOT_FOUND} !NOT_FOUND
RewriteRule ^product/([^./]+)([/]*)$ displayproduct.aspx?pid=${ProductMapFile:$1} [NC,L]

# if the entry is missiong, redirect somewhere else
RewriteCond ${mapfile:$1|NOT_FOUND} NOT_FOUND
RewriteRule ^product/([^./]+)([/]*)$ /404 [NC,R=301,L]


You can basically replace 404 with any non-existing page to generate 404 status... or you may create customized 404. ISAPI_Rewrite doesn't have flag to generate 404.

Regards
Andrew

User avatar
Posts: 16
Joined: 13 Nov 2012, 00:19

Re: showing 404 page on mapped page

16 Nov 2012, 22:31

A customized 404? How is that possible? Does this code has it?

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

Re: showing 404 page on mapped page

17 Nov 2012, 02:17

It is customized page, but it will return 301 redirect. In case you want ErrorDocument, you need to use Ape.

Regards
Andrew

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 16 guests