UrlRewritingNet and php.

While getting mad to let phpBB accept image tags with ampersends and question marks i decided to add something similar to the mod_rewrite in Apache, i have found on github the UrlRewritingNet project

My website works as you can see specifying the path in the "p" query string parameter, same goes for images. Plus requiring an image and specifying the path with an extra "size" parameter would build a resized image...but the parameters are not accepted in phpBB image tags...

The only problem (as of 2015 October 30) is that i had to modify the code to let it work with IIS7 adding a property on a class, the dll is available as a compiled dll file or on github until the owner does not update the respository.

Installation

Just copy the dll in the bin folder and setup the web.config :D

Configuration

I needed to have it configured on my hosting and this is waht i came up with. The main problem was that the default page was specified always in the configuration then calling

http://www.test.com/dir/

Resulted in

http://www.test.com/dir/default.aspx

The solution was to remove all default page references from the web.config and the UrlRewritingNet configuration

<?xml version="1.0"?>
<configuration>
  <configSections>
    <section name="urlrewritingnet"  
             requirePermission ="false" 
             type="UrlRewritingNet.Configuration.UrlRewriteSection, UrlRewritingNet.UrlRewriter"  />
  </configSections>
  <urlrewritingnet
    rewriteOnlyVirtualUrls="true"   
    contextItemsPrefix="QueryString"     
    defaultProvider="RegEx"
    xmlns="http://www.urlrewriting.net/schemas/config/2006/07" >
    <rewrites>
      <add name="Rewrite"  
        rewriteOnlyVirtualUrls="true"
        virtualUrl="^~/(image/)([a-zA-Z]+)/(.*).(jpg|jpeg|gif|png)"            
            rewriteUrlParameter="ExcludeFromClientQueryString" 
            destinationUrl="~/index.php?p=$3.$4&size=$2"
            ignoreCase="true" />
      </rewrites>
  </urlrewritingnet>
  <appSettings/>
  <system.web>
    <customErrors mode="Off">
    </customErrors>  
  </system.web>
  <system.webServer>
     <validation validateIntegratedModeConfiguration="false"/> 
     <modules runAllManagedModulesForAllRequests="true">
         <add name="UrlRewriteModule"
               type="UrlRewritingNet.Web.UrlRewriteModule, UrlRewritingNet.UrlRewriter" />   
     </modules>
  </system.webServer>
</configuration>

Now calling

http://www.kendar.org/img/thumb/php/mysqlphpicalendar/mysqlphpicalendar.00.png

Would result in

http://www.kendar.org/?p=/php/mysqlphpicalendar/mysqlphpicalendar.00.png&size=thumb

Yay :D


Last modified on: October 30, 2015