Special Characters

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 4
Joined: 13 Apr 2012, 09:27

Special Characters

13 Apr 2012, 12:36

The site I am working on deals with technical products - thus the source where I would generate my friendly URLs from can contain all sorts of special characters.

Things like brackets, quotes, full stops etc would not be uncommon at all.

I realise I will need to strip these down, and have been replacing spaces and slashes etc but how far should I go? For example they have a category called :

Fibre-Leads-Multimode-62.5125µm-OM1-2mm

That has a full stop and a µ charcter in it.

Is there a best practice for this sort of thing?

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

Re: Special Characters

16 Apr 2012, 19:01

Hello,

You escape full stop in your regular expression as following: \.
The µ can be shown differently, but each of the options suits one of the flags: NE or NU. Full description see here

Regards
Andrew

User avatar
Posts: 4
Joined: 14 Apr 2012, 17:03

Re: Special Characters

16 Apr 2012, 20:45

Basically all of my rewrite rules are generated from a CMS so everything has to go automatically. I had problems with using special characters, here is the final rewrite:
http://i42.tinypic.com/333l753.jpg

You might wonder why I am passing the &rewrite= querystring parameter and why it looks so messy.
  • I need the ?rewrite= parameter for two reasons:
    a) In case the visitor does not have access to the page and needs to be redirect to the login page, after login he can be redirected to the nice rewritten url /en/whatever.
    b) I am using .NET and have to use a FormRewriter to fix the 'action' attribute on forms. Because when the URL in the address bar of the browser says /some/rewrite and the <form action="actualpage.aspx"> you will get an error (I forgot which one but you can reproduce it quite easily). So my FormRewriter only has to get the actual rewrite from the querystring
    Code: Select all
      value = HttpContext.Current.Request.QueryString["rewrite"]
     

  • The &rewrite= querystring value looks this way because:
    a) I am using Uri.EscapeDataString() on the rewrite (/de/verkäufer) so that Request.QueryString works correctly. This creates %C3%A4 for the special 'ä' character. And all forward slashes (/) become %2F
    b) The percentages need to be escaped for ISAPI Rewrite

Hope this helps. Even if you're not using .NET you might have to use one of these techniques.

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 18 guests