Regular Expressions in Rewrite URL Module for IIS7

I have the following rewrite rule to add the .aspx extension if the url has no extension.

  <rule name="SimpleRewrite" stopProcessing="true"> <match url="^(.*(?&lt;=/)([^/.]*))$" /> <action type="Rewrite" url="{R:1}.aspx" /> </rule> 

However, the rule does not work:

 Error HTTP 500.52 - URL Rewrite Module Error. The expression "^(.*(?<=/)([^/.]*))$" has an invalid syntax. 

However, this regular expression works in .NET. What regular expressions are supported by the IIS Url Rewrite Module? How to make a positive statement about the look?

+4
source share
2 answers

maybe .*/[^/.]+$ will serve your needs? rewriting will just be "{R: 0} .aspx"

edit (in response to comment): if you want to include simple file names, you can write

 ^(.*/)?[^/.]+$ 
+2
source

It looks like there might be a simpler solution to your problem that won't require regular expressions, but if not, it might help.

Quick: try the IIS plugin for mod-rewrite, such as ISAPI_Rewrite Lite for complex regular expressions.

Long: A year ago, I did an ISS deployment on a Drupal site in which all primary, secondary and I believe that tertiary links should be handled by Drupal, but a deeper legacy should have served as normal (instead of being captured by Drupal 404).

We used ISAPI_Rewrite 3, the “port” (compatible syntax) of Apache mod_rewrite, to guide between legacy content and drupal, with a series of Rewrite filters and rules that will check for any content matching the URL in the legacy before allowing Drupal to process the rest.

http://www.helicontech.com/isapi_rewrite/

ISAPI_Rewrite Lite is free and has all the features I need. In addition, you can go shopping, Helicon is not the only company that created the Mod-Rewrite plugin for cloning for IIS.

+1
source

Source: https://habr.com/ru/post/1304289/


All Articles