elementor / wp2static-addon-s3

S3 deployment Add-on for WP2Static
The Unlicense
35 stars 23 forks source link

Feature Proposal: Optionally create "redirect pages" in S3 based on .htaccess file #8

Closed austinlangdon closed 4 years ago

austinlangdon commented 4 years ago

Problem: 301 redirect rules (defined in .htaccess) are not supported/included in automated S3 deployment scope, even though S3 has support for redirects.

Proposal: Add an optional feature that if enabled, fires at the end of the S3 deployment job to setup "redirect pages" in S3 bucket.

  1. Scan the .htaccess file for 301 redirect rules
  2. For each redirect rule detected, upload a zero-byte object to S3 bucket named as the Source URL, with the x-amz-website-redirect-location header set as the Target URL

For example, if a website has rule to 301 redirect /page1/ to /page2/, the deployment job would detect this rule, and upload a zero-byte object named /page1/index.html with the x-amz-website-redirect-location header value set as /page2/index.html.

Official AWS Documentation on this header: https://docs.aws.amazon.com/AmazonS3/latest/dev/how-to-page-redirect.html

austinlangdon commented 4 years ago

Example of 301 redirects within a .htaccess file:

<IfModule mod_rewrite.c>
RewriteRule ^terms$ /legal [R=301,L]
RewriteRule ^the-simple-answer-to-what-search-engine-marketing-is-and-how-it-can-help-your-business/$ /what-is-search-engine-marketing/ [R=301,L]
RewriteRule ^seo-tips-2017/$ /seo-tips-2019/ [R=301,L]
</IfModule>

The function would check and see these 3 rules in .htaccess, and then PUT 3 more objects into S3 bucket with the x-amz-website-redirect-location set.

john-shaffer commented 4 years ago

Noting here that #20 addresses this. However, I think the redirect detection functionality should be in core WP2Static.

austinlangdon commented 4 years ago

@john-shaffer thanks. Maulik works on my team and I asked him to work on this and also to create a PR.

I agree it makes sense to put detection in core. @leonstafford would you be open to letting us implement this in core? Or are you already working on it?

leonstafford commented 4 years ago

@austinlangdon, sorry I missed this one. Should be addressed in comment on https://github.com/WP2Static/wp2static-addon-s3/pull/20