Search code examples
phpumbracourlrewriting.net

Urlrewritingnet 301 redirect strange behavior


I migrated a site form a php system to Umbraco. I would like to redirect all the old urls (es: index.php? ...) to the current site root, so I wrote a rule:

<urlrewritingnet xmlns="http://www.urlrewriting.net/schemas/config/2006/07">
    <rewrites>        
        <add name="301RedirectDirUrlsOldSite" virtualUrl="^http\://www.mysite.it/index.php(.*)" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="http://www.mysite.it/" redirect="Domain" redirectMode="Permanent" ignoreCase="true" />
    </rewrites>
</urlrewritingnet> 

The rule works fine but the redirect incluse also the querystring parameters. For example is I fire www.mysite.it/index.php?p=10&url=test I've been redirect to the same url (without 404) but not to www.mysite.it only as I expect. Is there anything to change over my rule?


Solution

  • On php rewrites within Umbraco I use the following which should work for you:

    <add name="phpRewrites" virtualUrl="^~/(.*)\.php(.*)" rewriteUrlParameter="IncludeQueryStringForRewrite" redirect="Application" redirectMode="Permanent" destinationUrl="~/" ignoreCase="true" />
    

    The difference in the virtualUrl & destinationUrl may seem trivial - but give it a go.