Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(hotfix) Web.config redirects prod #1526

Merged
merged 7 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions pages/webconfig/web.config.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
---
permalink: /web.config
eleventyExcludeFromCollections: true
---

{%- set redirects = websiteRedirects | selectattr("original_url") -%}
<?xml version="1.0" encoding="utf-8"?>
{%- if redirects | groupby("original_url") | length !== redirects | length %} {#
duplicate "original_url" in data, throw error #} {{ 'web.config build fail ->
duplicate "original_url" in data' | error }} {% endif -%}
<configuration>
<system.webServer>
<staticContent>
<clientCache
cacheControlCustom="public"
cacheControlMode="UseMaxAge"
cacheControlMaxAge="97.00:00:00" />
<mimeMap fileExtension=".woff2" mimeType="application/font-woff2" />
<remove fileExtension=".webp" />
<mimeMap fileExtension=".webp" mimeType="image/webp" />
</staticContent>
<rewrite>
<rewriteMaps>
<rewriteMap name="410Removals" defaultValue="">
{%- for item in redirects | rejectattr("replacement_url") %}
<add key="{{item.original_url}}" value="foo" />
{%- endfor %}
</rewriteMap>
<rewriteMap name="StaticRewrites" defaultValue="">
{%- for item in redirects | selectattr("replacement_url") %}
<add key="{{item.original_url}}" value="{{item.replacement_url}}" />
{%- endfor %}
</rewriteMap>
</rewriteMaps>
<rules>
<rule
name="AddTrailingSlash BeforeStaticRewrites"
stopProcessing="true">
<match url="(^[^.]*[^/]$)" />
<action type="Redirect" url="{R:1}/" />
</rule>
<rule name="Static Rewrite Rule" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{StaticRewrites:{URL}}" pattern="(.+)" />
</conditions>
<action type="Redirect" url="{C:1}" />
</rule>
<rule name="410response" stopProcessing="true">
<conditions>
<add input="{410Removals:{URL}}" pattern=".+" />
</conditions>
<action
type="CustomResponse"
statusCode="410"
statusReason="Gone"
statusDescription="Gone. The requested resource is no longer available." />
</rule>
</rules>
<outboundRules>
<rule name="Add Strict-Transport-Security when HTTPS">
<!-- Preload HSTS here ... https://hstspreload.org/ -->
<match
serverVariable="RESPONSE_Strict_Transport_Security"
pattern=".*" />
<conditions>
<add input="{HTTPS}" pattern="on" ignoreCase="true" />
</conditions>
<action
type="Rewrite"
value="max-age=31536000; includeSubDomains; preload" />
</rule>
</outboundRules>
</rewrite>

<!-- Below block is for custom redirect for 404 error to 404.html -->
<httpErrors>
<remove statusCode="404" />
<error statusCode="404" path="404.html" />
<remove statusCode="403" />
<error statusCode="403" path="404.html" />
</httpErrors>
</system.webServer>
</configuration>
80 changes: 80 additions & 0 deletions src/_data/websiteRedirects.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
original_url,replacement_url
/business-profile.html,
/components/accordions.html,/components/accordion.html
/components/buttons.html,/components/button.html
/contact.html,/contact-us.html
/css/colortheme-/,/visual-design/color/
/general-landing.html,
/get-started/index.html,/get-started.html
/Getting-started.html,/get-started.html
/gulp.html,
/privacy.html,/privacy-policy.html
/profile-landing.html,
/sample/,/components.html
/sample/alert-banner.html,/components/alert.html
/sample/breadcrumb.html,/components/breadcrumb.html
/sample/buttons.html,/components/button.html
/sample/carousels.html,/patterns/banner.html
/sample/color-schemes.html,/visual-design/color.html
/sample/colorscheme-mono.html,/visual-design/color/?mono
/sample/colorscheme-oceanside.html,/visual-design/color/?oceanside
/sample/colorscheme-orangecounty.html,/visual-design/color/?orangecounty
/sample/colorscheme-sacramento.html,/visual-design/color/?sacramento
/sample/colorscheme-santabarbara.html,/visual-design/color/?santabarbara
/sample/colorscheme-santacruz.html,/visual-design/color/?santacruz
/sample/colorscheme-sierra.html,/visual-design/color/?sierra
/sample/colorscheme-trinity.html,/visual-design/color/?trinity
/sample/countdown.html,/components/countdown-timer.html
/sample/event-list.html,
/sample/figure.html,
/sample/form.html,/components/form-elements.html
/sample/gradient-backgrounds.html,/get-started/css-classes-shortcuts/gradient-backgrounds.html
/sample/hero-info.html,/patterns/banner.html
/sample/horizontal-rules.html,/components/horizontal-separator.html
/sample/icon-blocks.html,
/sample/icon-fonts.html,/visual-design/icons.html
/sample/index.html,/components.html
/sample/info-blocks.html,/get-started/css-classes-shortcuts/utility-css-classes.html
/sample/job-detail.html,
/sample/job-list.html,
/sample/layout-about.html,
/sample/layout-contact.html,
/sample/layout-events.html,
/sample/layout-faq.html,
/sample/layout-news.html,/patterns/newsroom.html
/sample/layout-profile.html,/components/executive-profile.html
/sample/layout-services.html,
/sample/layouts.html,/patterns.html
/sample/lists.html,/components/lists.html
/sample/navigation-dropdown.html,/structure/site-navigation.html
/sample/navigation-full-width-icons.html,/structure/site-navigation.html
/sample/navigation-full-width-utility.html,/structure/site-navigation.html
/sample/navigation-full-width.html,/structure/site-navigation.html
/sample/navigation-megamenu-flex.html,/structure/site-navigation.html
/sample/navigation-megamenu-original.html,/structure/site-navigation.html
/sample/navigation-megamenu.html,/structure/site-navigation.html
/sample/navigation-sidebar.html,/components/side-navigation.html
/sample/navigation-single.html,/structure/site-navigation.html
/sample/navsamples.html,/structure/site-navigation.html
/sample/news-detail.html,/patterns/card-grid.html
/sample/number-counter.html,/components/number-counter.html
/sample/page-templates.html,/patterns.html
/sample/panes.html,
/sample/parallax.html,/components/parallax.html
/sample/profile-list.html,
/sample/progress-bars.html,/components/progress-bar.html
/sample/progress-blocks.html,/components/progress-bar.html
/sample/publications.html,/patterns/list-of-articles-or-content.html
/sample/sections.html,
/sample/sticky-footer.html,/structure/footer.html
/sample/text-accent.html,/get-started/css-classes-shortcuts/text-accent-colors.html
/sample/timeline.html,/patterns/progress-tracker.html#Horizontal-tracker
/sample/typography.html,/visual-design/typography.html
/search-directory.html,
/service-profile.html,
/shortcuts.html,/get-started/css-classes-shortcuts/
/structure/layouts.html,/structure.html
/structure/settings.html,
/update.html,/whats-new.html
/use.html,/conditions-of-use.html
/visual-design.html,/whats-new.html#Visual-design
25 changes: 25 additions & 0 deletions src/_data/websiteRedirects.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const fs = require("fs");
const { parse } = require("csv-parse/sync");

module.exports = () => {
const csvFilePath = `${__dirname}/websiteRedirects.csv`;

// Read and parse CSV file at csvFilePath
const fileData = fs.readFileSync(csvFilePath, "utf8");
const iconDataCsv = parse(fileData, {
columns: true,
skip_empty_lines: true
});

const iconDataJson = [];

// Build iconDataJson from parsed CSV data
iconDataCsv.forEach(item => {
iconDataJson.push({
original_url: item.original_url,
replacement_url: item.replacement_url
});
});

return iconDataJson;
};
17 changes: 0 additions & 17 deletions src/root/web.config

This file was deleted.