Skip to content
Permalink
Browse files

URL Configuration, alias to hostname redirect - adding "Redirect Perm…

…anently (HTTP 301)" option (before all redirects were always HTTP 302)
  • Loading branch information...
mawtex committed May 24, 2019
1 parent 47b9027 commit ca43b1c7fbdf5df21684b367e4ebcb299678865f
@@ -1,4 +1,4 @@
using System;
using System;
using System.Globalization;
using System.Web;
using Composite.Core.Extensions;
@@ -220,7 +220,14 @@ static bool CheckForHostnameAliasRedirect(HttpContext httpContext)

string newUrl = request.Url.AbsoluteUri.Replace("://" + hostname, "://" + hostnameBinding.Hostname);

httpContext.Response.Redirect(newUrl, false);
if (hostnameBinding.UsePermanentRedirect)
{
httpContext.Response.RedirectPermanent(newUrl, false);
}
else
{
httpContext.Response.Redirect(newUrl, false);
}
httpContext.ApplicationInstance.CompleteRequest();
return true;
}
@@ -1,4 +1,4 @@
using System;
using System;
using Composite.Data.Hierarchy;
using Composite.Data.Hierarchy.DataAncestorProviders;
using Microsoft.Practices.EnterpriseLibrary.Validation.Validators;
@@ -70,5 +70,14 @@ public interface IHostnameBinding : IData
[DefaultFieldBoolValue(false)]
[ImmutableFieldId("{1F45F2E7-2FAF-4F33-ACCA-BFF32EF7818A}")]
bool EnforceHttps { get; set; }

/// <summary>
/// When set to <value>true</value>, the system will use "HTTP 301 Permanent Redirect" when
/// redirecting from an alias to the hostname.
/// </summary>
[StoreFieldType(PhysicalStoreFieldType.Boolean)]
[DefaultFieldBoolValue(true)]
[ImmutableFieldId("{d933184a-19c1-4292-8e2e-f4a1a163f087}")]
bool UsePermanentRedirect { get; set; }
}
}
@@ -1,4 +1,4 @@
<cms:formdefinition xmlns:cms="http://www.composite.net/ns/management/bindingforms/1.0" xmlns="http://www.composite.net/ns/management/bindingforms/std.ui.controls.lib/1.0" xmlns:f="http://www.composite.net/ns/management/bindingforms/std.function.lib/1.0">
<cms:formdefinition xmlns:cms="http://www.composite.net/ns/management/bindingforms/1.0" xmlns="http://www.composite.net/ns/management/bindingforms/std.ui.controls.lib/1.0" xmlns:f="http://www.composite.net/ns/management/bindingforms/std.function.lib/1.0">
<cms:bindings>
<cms:binding name="Id" type="System.Guid" optional="true" />
<cms:binding name="Hostname" type="System.String" optional="true" />
@@ -9,6 +9,7 @@
<cms:binding name="PageNotFoundUrl" type="System.String" optional="true" />
<cms:binding name="Aliases" type="System.String" optional="true" />
<cms:binding name="EnforceHttps" type="System.Boolean" />
<cms:binding name="UsePermanentRedirect" type="System.Boolean" />
</cms:bindings>
<cms:layout>
<cms:layout.label>
@@ -67,6 +68,11 @@
<cms:bind source="Aliases" />
</TextArea.Text>
</TextArea>
<CheckBox Label="${Orckestra.Tools.UrlConfiguration, HostnameBinding.UsePermanentRedirect.Label}" ItemLabel="${Orckestra.Tools.UrlConfiguration, HostnameBinding.UsePermanentRedirect.ItemLabel}" Help="${Orckestra.Tools.UrlConfiguration, HostnameBinding.UsePermanentRedirect.Help}">
<CheckBox.Checked>
<cms:bind source="UsePermanentRedirect" />
</CheckBox.Checked>
</CheckBox>
</FieldGroup>
</cms:layout>
</cms:formdefinition>
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<strings>
<!-- Element tree -->
<string key="Tree.ConfigurationElementLabel" value="URL Configuration" />
@@ -37,4 +37,7 @@
<string key="HostnameBinding.Custom404Page.Help" value="Url to which request will be redirected in the case there's a request to non-existent c1 page" />
<string key="HostnameBinding.Aliases.Label" value="Alias hostnames" />
<string key="HostnameBinding.Aliases.Help" value="Hostnames from which all requests will be redirected to the current hostname" />
<string key="HostnameBinding.UsePermanentRedirect.Label" value="Alias Redirect" />
<string key="HostnameBinding.UsePermanentRedirect.ItemLabel" value="Use permanent redirect (HTTP 301)" />
<string key="HostnameBinding.UsePermanentRedirect.Help" value="When redirecting from an alias to the common hostname, a permanent redirect will tell visitors (browsers and search engines) that this redirect should be considered permanent and may be cached. Checking this box has a positive effect on SEO, provided the alias rule do not change in the near future" />
</strings>
@@ -658,6 +658,7 @@
<Content Include="Composite\localization\Composite.Plugins.Components.en-us.xml" />
<Content Include="Composite\localization\Composite.Plugins.TimezoneDisplayNames.en-us.xml" />
<Content Include="Composite\localization\Composite.Plugins.TimezoneAbbreviations.en-us.xml" />
<Content Include="Composite\localization\Orckestra.Tools.UrlConfiguration.en-us.xml" />
<Content Include="Composite\scripts\source\top\core\ContextContainer.js" />
<Content Include="Composite\scripts\source\top\core\ImageProvider.js" />
<Content Include="Composite\scripts\source\top\interfaces\IContextContainerBinding.js" />

0 comments on commit ca43b1c

Please sign in to comment.
You can’t perform that action at this time.