Kentico 9 sync Server Service URL case sensitivity - iis-7

I have a rewrite rule to make the URL all lower case. It ran before anything else. Site would load fine, things were good, but sync was broken. After some trial and errors I figured it was the rewrite rule. I also tried the build in rule for this with IIS and same issues.
With that, is it possible to make a change so the path is all lower case? I didn't think this would have been an issue but it seems to be.
Here is my rule
<rule name="Convert to lower case" stopProcessing="true">
<match url=".*[A-Z].*" ignoreCase="false" />
<action type="Redirect" url="{ToLower:{R:0}}" redirectType="Permanent" />
</rule>

The Content Sync isn't case sensitive that I'm aware of. You can use the setting within Kentico to do the same as the IIS rewrite rule with no effect on the other system pages. Have you looked into this? I'd make this edit before making a rewrite rule in IIS.
Settings>URLs & SEO>SEO - URLs>Redirect invalid case URLs to their correct versions = lower case.

Related

Rewrite rule that works for different domains and subdomains

I am wondering if it is possible to set up a rewrite rule where you do not specify the domain, only the page accessed and the page to redirect to. My goal for this is to not have to have different versions of the same rule for different sites (i.e. dev.mysite.com, qa.mysite.com, etc), so one rule works for multiple subdomains. For example, I need to redirect someone going to dev.mysite.com/mexico to mx.dev.mysite.com/es/mexico, but that also has to work for QA. Additionally, production has a slightly different domain which would make this even more difficult. This is what I came up with - it definitely needs work:
<rule name="Test Mexico Redirect">
<match url="^mexico"/>
<action type="Redirect" url="http://mx.{R:2}/es/mexico" redirectType="Permanent"/>
</rule>
Unfortunately it just does not work; I get a blank page. Probably because {R:2} is looking for the domain in the rule and one isn't specified. I can't think of a way to do this, because not even the domain is the same across all environments.
It would be cool if you could use regex in the <action> element, then I would do something like this: ^(mx\.).*com/es/mexico.
It's possible using {HTTP_HOST} and back references like {C:#}. The IIS Rewrite module is extremely useful for setting this up. Here is a screenshot with some notes that explains how it's done:
By using {HTTP_HOST} and conditions I was able to make a rewrite rule that can apply to all environments. The actual XML result:
<rule name="Mexico Redirect" stopProcessing="true">
<match url="mexico" />
<conditions>
<add input="{HTTP_HOST}" pattern="^((?!mx))" />
<add input="{CACHE_URL}" pattern="^(.+)://" />
</conditions>
<action type="Redirect" url="{C:1}://mx.{HTTP_HOST}/es/search" redirectType="Temporary" />
</rule>
Also I may have been incorrect saying you won't need to recycle the app pool with a Temporary (307) redirect. I still needed to recycle it but only in production... no verdict on this yet.

Owin URL Rewrite to different port

We have a series of smaller APIs part of a larger system, each running in their own sites on an IIS machine.
To hide our internal architecture, we've created a series of IIS rewrite rules:
<rule name="AuthServer" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^auth/.*" />
<action type="Rewrite" url="https://localhost:4000/{R:0}" />
</rule>
However, we need to extend this system and make it testable.
We've tried:
if (context.Request.Uri.AbsoluteUri.EndsWith("test"))
{
context.Request.Path = new PathString("/rewritten");
}
But this only allows us to change the path. We need to rewrite to a different port/site.
Can this be done?
We didn't find a way to do this, so we ended up using:
https://msdn.microsoft.com/en-us/library/microsoft.web.administration.servermanager.getwebconfiguration(v=vs.90).aspx
To dynamically update the web.config rewrite rules from code. It works fine, and is testable (though not locally hosted).

IIS URL Rewrite based on root url

I'm trying to rewrite a url:
www.mydomain.com/urlfolder/filename.aspx
to point to
www.mydomain.com/urlfolder/newfile.aspx
My web config has the following:
<rule name="PageRedirection" enabled="true" stopProcessing="true">
<match url="urlfolder/filename.aspx" />
<action type="Redirect" url="urlfolder/newfile.aspx" redirectType="Permanent" />
</rule>
the problem is that this is catching urls such as:
www.mydomain.com/subdirectory/urlfolder/filename.aspx
I tried to change my url to be
but the ^ didn't work. It also seems ~/ doesnt work to specify the root either.
How would I go about specifying this url from the root, w/o putting in an absolute path.
I also have:
testsite.mydomain.com/
and I want the SAME web.config deployed there to work.
Thanks!
I know this question is nearly 4 years old, so you've probably long since moved on from needing an answer.
^ should work though:
<rule name="PageRedirection" enabled="true" stopProcessing="true">
<match url="^urlfolder/filename.aspx" />
<action type="Redirect" url="urlfolder/newfile.aspx" redirectType="Permanent" />
</rule>
^ specifies the beginning of the path string, so whatever you put after the ^ would match only what appears right after the site root and a slash.
e.g.
www.example.com/urlfolder/filename.aspx
would match.
www.example.com/subdirectory/urlfolder/filename.aspx
would NOT match.
The only reason I can think of why it would match /subdirectory/urlfolder/filename.aspx as you say, is that there is a copy of your web.config
in /subdirectory/ in which case www.example.com/subdirectory/ is treated as the root.
If that's the case and your web.config is being copied to places other than your root directory, another option is to add the rule in %windir%\system32\inetsrv\config\ApplicationHost.config instead of a web.config. This is the file that contains all settings that apply to all of IIS on your machine, not just a particular site. In my experience, Visual Studio will refuse to open this file. However, you can edit the file in a different editor, or set the rewrite rules through the IIS GUI.
In the GUI, at the top level of the file tree, the tools available at this level include the URL Rewrite utility, and rules set there write to ApplicationHost.config.
Hope this helps

iis rewrite url with dot at end of url

I have some external links coming into my site which mistakenly had a period added to their ends. (so, I can't fix them). Since inbound links are always good, I want to redirect these links to a legit page. I've tried a number of rules in the urlrewrite module for iis.5 and nothing seems to capture this url.
I've seen other questions on here regarding asp.net urls with periods at the end, but I'm trying to capture this one at the IIS rewrite module level. Any pointers on making this work?
This is quite an old one but as i was facing similar issue recently i've decided to post my findings...
I assume that one of modules that run prior to url-rewrite module terminates, with an exception, preventing request from continuing to url-rewrite (i suspect some security checks). Thus it is not possible to resolve your issue with url-rewrite.
One possible workaround could be to redirect requests ending with dot '.' at the very early stage in Global.asax, like here:
protected void Application_PreSendRequestHeaders(object sender, EventArgs e)
{
if (Context.Request.RawUrl.EndsWith(".aspx."))
{
//permanent redirect and end current request...
Context.Response.RedirectPermanent(Context.Request.RawUrl.TrimEnd('.'), true);
}
}
That might be far from optimal answer but at least it gets job done ;)
I used a solution that removes all trailing dots at the web.config level:
<rule name="RemoveTrailingDots" stopProcessing="false">
<match url="^(.*[^.])\.+$" />
<action type="Rewrite" url="{R:1}" />
</rule>
This rule just rewrites the request url internally at the beginning of my rewrite rules, allowing the request to process through the normal rules instead of being caught upstream
If you don't have any more rules to apply, and just want to redirects anything with dots at the end, just change the action type to Redirect (case sensitive)
If you have a fixed set of inbound links that are incorrect, you can concentrate on redirecting the main part of the URL, rather than the dot.
For example, with this URL:
http://www.example.com/index.html.
Have your IIS Rewrite look for a URL matching "^index.html.*" and redirect to the page you need. That should catch the URL both with and without the dot.
On IIS 8.5 I implemented something substantially similar to that proposed by GWR but with one subtle change. I needed the attribute appendQueryString="true" on the Rewrite action tag. (Perhaps this was the default back in 2016, but now needs to be specified.)
Here's what worked for me:
<system.webServer>
<modules>
...
</modules>
<validation validateIntegratedModeConfiguration="false" />
<rewrite>
<rules>
<rule name="RemoveTrailingDots">
<match url="^(.*[^.])\.+$" />
<action type="Rewrite" url="{R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
I had to install the URL Rewrite feature from here: https://www.iis.net/downloads/microsoft/url-rewrite

How do I remove index.aspx from a url using web.config?

How would one redirect from www.example.com/section/index.aspx to www.example.com/section using rewrite rules in web.config? It would also have to work for various levels such as www.example.com/parent/child
*Noting that I do not have access to the server. I can basically just edit the web.config file and tell the server to rebuild the application.
Your best bet is to use the IIS7 URL Rewrite Module - but you would need to install this on the server. It's pretty easy to use and powerful at the same time. It may already be installed if you're hosted, because although it's not installed by default, it is from Microsoft and pretty frequently used.
If you're on 2.0 or greater of asp.net, you can add a urlMappings section to the web.config:
<system.web>
<urlMappings enabled="true">
<add url="~/Section" mappedUrl="~/Section/index.aspx"/>
</arlMappings>
</system.web>
But this has some issues : Firstly, if the URL requested isn't handled by the ASP.Net module, or isn't delivered to your application, the rewrite never happens. This could occur because you aren't hitting a ".aspx" file, for example. Also, in some configurations, the file you request needs to exist. Another issue is that there are no wildcard rules supported, so you would have to add rules to rewrite all possible paths individually.
And finally, there are asp.net rewrite httpmodules you could drop in the bin directory and add to your web.config. Here's some (possibly outdated) options by ScottGu for url rewriting.
This is probably massively disgusting but by creating rules for each possible level I was able to rewrite all paths dropping index.aspx from the url.
starting with
<rule name="Migrate to PHP">
<match url="^([_0-9a-z-]+).aspx"/>
<action type="Redirect" redirectType="Permanent" url="/"/>
</rule>
and ending with
<rule name="Migrate to PHP all the way">
<match url="^([_0-9a-z-]+)/([_0-9a-z-]+)/([_0-9a-z-]+)/([_0-9a-z-]+)/([_0-9a-z-]+).aspx"/>
<action type="Redirect" redirectType="Permanent" url="{R:1}/{R:2}/{R:3}/{R:4}"/>
</rule>

Resources