Browse Source

Base url fix

pull/1/head
Sebastian 9 years ago
parent
commit
ae6526d2a0
  1. 12
      src/Squidex/Pipeline/SingleUrlsMiddleware.cs
  2. 3
      src/Squidex/Startup.cs
  3. 2
      src/Squidex/appsettings.Production.json

12
src/Squidex/Pipeline/SingleUrlsMiddleware.cs

@ -27,7 +27,7 @@ namespace Squidex.Pipeline
public async Task Invoke(HttpContext context) public async Task Invoke(HttpContext context)
{ {
var currentUrl = string.Concat(context.Request.Scheme, context.Request.Host, context.Request.Path); var currentUrl = string.Concat(context.Request.Scheme, "//:", context.Request.Host, context.Request.Path);
var hostName = context.Request.Host.ToString().ToLowerInvariant(); var hostName = context.Request.Host.ToString().ToLowerInvariant();
if (hostName.StartsWith("www")) if (hostName.StartsWith("www"))
@ -36,7 +36,9 @@ namespace Squidex.Pipeline
} }
var requestPath = context.Request.Path.ToString(); var requestPath = context.Request.Path.ToString();
if (requestPath.EndsWith("/") == false)
if (!requestPath.EndsWith("/") &&
!requestPath.Contains("."))
{ {
requestPath = requestPath + "/"; requestPath = requestPath + "/";
} }
@ -46,9 +48,13 @@ namespace Squidex.Pipeline
if (!string.Equals(newUrl, currentUrl, StringComparison.OrdinalIgnoreCase)) if (!string.Equals(newUrl, currentUrl, StringComparison.OrdinalIgnoreCase))
{ {
logger.LogError("Invalid url: {0} instead {1}", currentUrl, newUrl); logger.LogError("Invalid url: {0} instead {1}", currentUrl, newUrl);
}
context.Response.Redirect(newUrl, true);
}
else
{
await next(context); await next(context);
} }
} }
} }
}

3
src/Squidex/Startup.cs

@ -93,7 +93,10 @@ namespace Squidex
loggerFactory.AddConsole(); loggerFactory.AddConsole();
loggerFactory.AddDebug(); loggerFactory.AddDebug();
if (!Environment.IsDevelopment())
{
app.UseMiddleware<SingleUrlsMiddleware>(); app.UseMiddleware<SingleUrlsMiddleware>();
}
if (Environment.IsDevelopment()) if (Environment.IsDevelopment())
{ {

2
src/Squidex/appsettings.Production.json

@ -1,5 +1,5 @@
{ {
"identity": { "identity": {
"baseUrl": "http://squidex.io" "baseUrl": "https://squidex.io"
} }
} }
Loading…
Cancel
Save