Sets SSL redirection as permanent for SEO reasons (#8503)

Fixes #8502
This commit is contained in:
Hermes Sbicego 2021-09-16 19:03:00 +02:00 committed by GitHub
parent e447561cfe
commit d51418b2c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 5 deletions

View File

@ -29,7 +29,7 @@ namespace Orchard.SecureSocketsLayer.Filters {
var secure =
(user != null && user.Identity.IsAuthenticated) ||
_sslService.ShouldBeSecure(filterContext);
var usePermanentRedirect = settings.UsePermanentRedirect;
var request = filterContext.HttpContext.Request;
// redirect to a secured connection ?
@ -41,7 +41,7 @@ namespace Orchard.SecureSocketsLayer.Filters {
filterContext.ActionDescriptor.ControllerDescriptor.ControllerName,
filterContext.RequestContext.RouteData.Values));
filterContext.Result = new RedirectResult(secureActionUrl);
filterContext.Result = new RedirectResult(secureActionUrl, usePermanentRedirect);
return;
}
@ -56,7 +56,7 @@ namespace Orchard.SecureSocketsLayer.Filters {
filterContext.ActionDescriptor.ControllerDescriptor.ControllerName,
filterContext.RequestContext.RouteData.Values));
filterContext.Result = new RedirectResult(insecureActionUrl);
filterContext.Result = new RedirectResult(insecureActionUrl, usePermanentRedirect);
}
}
@ -67,4 +67,4 @@ namespace Orchard.SecureSocketsLayer.Filters {
return url;
}
}
}
}

View File

@ -6,6 +6,7 @@ using Orchard.ContentManagement.FieldStorage.InfosetStorage;
namespace Orchard.SecureSocketsLayer.Models {
public class SslSettings {
public bool Enabled { get; set; }
public bool UsePermanentRedirect { get; set; }
public string Urls { get; set; }
public bool SecureEverything { get; set; }
public bool CustomEnabled { get; set; }
@ -37,6 +38,14 @@ namespace Orchard.SecureSocketsLayer.Models {
set { this.As<InfosetPart>().Set<SslSettingsPart>("Enabled", value.ToString()); }
}
public bool UsePermanentRedirect {
get {
var attributeValue = this.As<InfosetPart>().Get<SslSettingsPart>("UsePermanentRedirect");
return !String.IsNullOrWhiteSpace(attributeValue) && Convert.ToBoolean(attributeValue);
}
set { this.As<InfosetPart>().Set<SslSettingsPart>("UsePermanentRedirect", value.ToString()); }
}
public bool CustomEnabled {
get {
var attributeValue = this.As<InfosetPart>().Get<SslSettingsPart>("CustomEnabled");

View File

@ -205,7 +205,8 @@ namespace Orchard.SecureSocketsLayer.Services {
SecureEverything = settingsPart.SecureEverything,
SecureHostName = settingsPart.SecureHostName,
InsecureHostName = settingsPart.InsecureHostName,
Enabled = settingsPart.Enabled
Enabled = settingsPart.Enabled,
UsePermanentRedirect = settingsPart.UsePermanentRedirect
};
});
}

View File

@ -18,6 +18,11 @@
@Html.TextBoxFor(m => m.InsecureHostName, new { @class = "textMedium" })
@Html.Hint(T("(Mandatory) The host name non-secured traffic should be redirected to (e.g. localhost:30321, mydomain.com). Don't include the protocol or anything else than the host name. A port can be specified after a colon if necessary (e.g. dev.127-0-0-1.org.uk:4333)."))
</div>
<div>
@Html.EditorFor(m => m.UsePermanentRedirect)
<label for="@Html.FieldIdFor(m => m.UsePermanentRedirect)" class="forcheckbox">@T("Enable Permanent redirection")</label>
@Html.ValidationMessage("UsePermanentRedirect", "*")
</div>
<div>
@Html.EditorFor(m => m.SecureEverything)
<label for="@Html.FieldIdFor(m => m.SecureEverything)" class="forcheckbox">@T("Force SSL on all pages")</label>