Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • ianhoughton 281 posts 605 karma points c-trib
    Sep 15, 2010 @ 17:49
    ianhoughton
    0

    Case insensitive URL rewrite rule

    I have a need to redirect incoming URL's like domain.co.uk/Services.aspx to domain.co.uk/services.aspx

    Is this something to be completed using ISAPI or in the UrlRewriting.config file ?

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Sep 15, 2010 @ 18:13
    Tom Fulton
    0

    There is an ignoreCase option on the UrlRewriting.config rewrites, so I imagine something like this would work (haven't tested):

    <add name="MyRedirect"
    ignoreCase="false"
    rewriteUrlParameter="IncludeQueryStringForRewrite"
    virtualUrl="http://domain.co.uk/Services.aspx"
    redirectMode="Permanent"
    destinationUrl="http://domain.co.uk/services.aspx" />

  • ianhoughton 281 posts 605 karma points c-trib
    Sep 15, 2010 @ 22:09
    ianhoughton
    0

    What about if I wanted a wildcard redirect i.e any uppercase URL to a lowercase URL ??

    This is my current rewrite rule in .htaccess file to add www to non-www addresses:

    RewriteEngine on

    RewriteCond %{HTTPS} (on)?

    RewriteCond %{HTTP:Host} ^(?!www\.)(.+)$ [NC]

    RewriteCond %{REQUEST_URI} (.+)

    RewriteRule .? http(?%1s)://www.%2%3 [R=301,L]

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Sep 16, 2010 @ 14:52
    Tom Fulton
    0

    Sorry, misunderstood your question.

    You could match uppercase characters in URLs in UrlRewriting with  /(.*[A-Z].*), but I can't see any way to convert them to lowercase in the destination URL without using some .NET code.

    I don't know much about .htaccess, but this example seems to work using IIS7 Rewrite Module:  http://www.webmasterworld.com/microsoft_asp_net/4027908.htm

     

  • ianhoughton 281 posts 605 karma points c-trib
    Sep 16, 2010 @ 15:28
    ianhoughton
    0

    Thanks Tom, I've hopefully sorted it using a .htaccess file.

    RewriteEngine on 

    RewriteBase

    #This section ensures the URL is changed to include the www

    RewriteCond %{HTTPS} (on)? 

    RewriteCond %{HTTP_HOST} ^(?!www\.)(.+)$ [NC] 

    RewriteCond %{REQUEST_URI} (.+) 

    RewriteRule .? http(?%1s)://www.%2%3 [R=301,L] 

    #This section rewrites any uppercase characters to lowercase

    RewriteCond %{HTTP_HOST} (.*) 

    RewriteRule ^(.*[A-Z].*)$ http\://%1$1 [R=301,CL,L]

  • ianhoughton 281 posts 605 karma points c-trib
    Sep 16, 2010 @ 23:19
    ianhoughton
    0

    I knew if was too good to be true..... the .htaccess file works on the client side of the website but in the Umbraco backend its causing problems when saving in the settings and developers tabs.

    I'm now getting errors when trying to save css / templates or xslt files.

  • ianhoughton 281 posts 605 karma points c-trib
    Oct 30, 2010 @ 16:00
    ianhoughton
    0

    Anyone know how to achieve this using the inbuilt rewrite engine in Umbraco:

     <rules> 
    <rule name="Convert to lower case" stopProcessing="false"> 
    <match url=".*[A-Z].*" ignoreCase="false"/> 
    <conditions> 
    <!-- The following condition prevents rule from rewriting requests to .axd files --> 
    <add input="{URL}" negate="true" pattern="\.axd$"/> 
    </conditions> 
    <action type="Redirect" url="{ToLower:{R:0}}" redirectType="Permanent"/> 
    </rule> 

    I need to convert www.domain.co.uk/Services.aspx to www.domain.co.uk/services.aspx using a wildcard type pattern. 

  • nehakakar 15 posts 85 karma points
    Jul 10, 2023 @ 22:36
    nehakakar
    0

    Add a rewrite rule

    Inside the

    <add name="CaseInsensitiveRedirect" redirect="Domain" ignoreCase="true" compareBy="ToLower" rewriteUrlParameter="ExcludeFromClientQueryString">
      <match url=".*" />
      <conditions logicalGrouping="MatchAll">
        <add input="{URL}" pattern="^[A-Z]" />
        <add input="{URL}" pattern="^/(.*)\.aspx$" />
      </conditions>
      <action type="Redirect" url="{ToLower:{R:1}}.aspx" />
    </add>
    

    The added rewrite rule will match any incoming URL that starts with an uppercase letter and ends with .aspx. It will then perform a case-insensitive redirect to the lowercase version of the URL.

Please Sign in or register to post replies

Write your reply to:

Draft