mod_rewrite to IIS issue

I’m having a weird issue on IIS with a converted mod_rewrite rule involving hyphens.

This does NOT work:
This does work:

The actual URL does not contain a hyphen. I can’t figure out why the server demands that the hyphen is present.

<rule name="View Post" stopProcessing="true">
	<match url="^post/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$" ignoreCase="false" />
	<action type="Rewrite" url="/post.php?post_url_id={R:1}&amp;post_url={R:2}" appendQueryString="false" />

First, the ‘M$’ code isn’t overly complex, but rather it uses a structured format easily readable with standard libraries.

As for the answer, I suck at regexes, but I think you need to escape that ‘-’ as that is a control character for regexes.


Sorry, that’s M$ code which is typically over complex. Since this is the Apache forum, I’ve move your thread to the Server forum where our IIS guys hang out.


Eek! Someone did it while I was responding!

As for your code, it (the regex) appears to be fine but I’m not familiar with this syntax.



Thanks, Wyatt!

Actually, in the Apache (original) mod_rewrite, the character range definition uses hyphens to define character ranges so it has to be either the first or last character in the definition to remove the ambiguity (FIRST is preferred). It took Wyatt (our “paid M$ Shill”) to see that M$ likes to escape characters rather than rely on their positioning! :tup:



Thank you. That was it :slight_smile: