When migrating websites often dead URLs happen since old website used different URL structure or technology. Correct 301 "permanent" redirect is important for SEO friendly migrations.
Example:
Old page https://example.com/product/coca-cola-bottle.html
moved in our JSF project to https://example.com/p/coca-cola-1-l/1000
Concept
We will save those mappings in our database and add them to our JSF application.
If an URL is requested that is not valid or rewritten we want to check the current requested URL if it exists in our database and redirect to the new target.
Some Ideas?
Right now i implemented @WebFilter version using an injected bean to lookup the mapping.
I would start by including the rewrite-integration-cdi
module:
Then create a CDI bean/Java class that can access your database.
Inject an instance of that class into your Rewrite ConfigurationProvider
, then use it to build / create your Rewrite rules.
Here is an example of both @Inject
ing beans into your ConfigurationProvider, and also defining custom HTTP operations:
Depending on how dynamic you want your database lookups to be, you could either preload them at startup time (when the Config is built), or load & cache them inside the Request/Response lifecycle itself using a custom HttpCondition
and `HttpOperation:
Then use those operations in your ConfigurationProvider
to perform the database operations. Essentially you will do something like this, but check the database to see if the requested URL is a ‘known/stored’ redirect:
And then use an custom HttpOperation
to perform the actions you want to take.
You could also technically just use a Condition
that matches all requests, and an HttpOperation
That only takes action if there is a database entry.
All that said, this sounds more complicated than it is, but there’s no good example I can find to link to that does exactly what you want, so I’m trying to piece it together.