Skip to content

Instantly share code, notes, and snippets.

@cfalzone
Created June 11, 2014 11:50
Show Gist options
  • Save cfalzone/e4a47ca5f781d94aa6b4 to your computer and use it in GitHub Desktop.
Save cfalzone/e4a47ca5f781d94aa6b4 to your computer and use it in GitHub Desktop.
Rewrite Rules in Activator
public class AquentActivator extends ExtendedBundleActivator {
@Override
public void start ( BundleContext ctx ) throws Exception {
// Initializing services
initializeServices(ctx);
// Add Rewrite Rules
addRewriteRules();
}
private void addRewriteRules() throws Exception {
// Rewrite rule for legacy Lead Form Handler
addRewriteRule("^/leadForm$", "/app/leadForm", "forward", "LegacyLeadFormHandlerRedirector");
CMSFilter.addExclude("/leadForm");
// Rewrite Rule for Legacy Vote Handler
addRewriteRule("^/votes$", "/app/votes", "forward", "LegacyVotesRedirector");
CMSFilter.addExclude("/votes");
// Rewrite Rule for JDL Detail pages
addRewriteRule("^/hire-talent/job-description-library/([\\-a-zA-Z]+)([0-9]+)",
"/hire-talent/job-description-library/details.htm?jobId=$2",
"forward", "JDL");
// Rewrite Rule for Cross Domain Web Fonts
// This allows web fonts to be shared across hosts, primarily a cross-site security restriction in Firefox.
NormalRule rule = new NormalRule();
rule.setName("CrossDomainWebFontsHeader");
rule.setFrom("\\.(eot|ttf|otf|woff)");
SetAttribute set = new SetAttribute();
set.setType("response-header");
set.setName("Access-Control-Allow-Origin");
set.setValue("*");
rule.addSetAttribute(set);
addRewriteRule(rule);
// Rewrite Rule for AD Postcard Campaign Redirector
// Necessary for a redirection URI for a print postcard. Put in place 12.05.04
addRewriteRule("^/ad/(.*)", "/go/$1?src=aq-adaware-nas-052412", "permanent-redirect", "ADPostcardCampaignRedirector");
// Rewrite Rule for Aquent Federal Work Samples
// Provides URL Map style functionality for the Aquent Samples structure on aquent.com, as the URL Map Pattern is assigned on aquentstudios.com.
addRewriteRule("^/federal/samples/([a-zA-Z0-9\\-]+)", "/federal/portfolio-detail.htm?urlTitle=$1", "forward", "AquentSamplesURLMap");
// Rewrite Rule for Old Webcast Folder Migration
// The old webcasts in the /learn_more folder had to be moved
rule = new NormalRule();
rule.setName("OldWebcastFolderMigration");
rule.setFrom("^/learn_more/resources/files/([a-zA-Z0-9\\-_]+)/([a-zA-Z0-9\\-_]+)\\.htm");
rule.setTo("/webcasts/migrated/$1/$2.htm");
rule.setToType("permanent-redirect");
Condition cond = new Condition();
cond.setType("server-name");
cond.setValue("(\\.)?aquent\\.");
rule.addCondition(cond);
addRewriteRule(rule);
}
@Override
public void stop ( BundleContext ctx ) throws Exception {
// Remove the Rewrite Rules
unregisterRewriteRule();
CMSFilter.removeExclude("/leadForm");
CMSFilter.removeExclude("/votes");
// Unregister all the bundle services
unregisterServices( ctx );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment