I have generated my WordPress website as static html and deployed it to s3 bucket to serve as static website.
Here is my website endpoint: wwwalls.com
My SEO team wants that the page URLs must not contain trailing slashes, but I could not find any document online that could allow me to get rid of trailing slashes from the URL eg : https://wwwalls.com/demo leads to https://wwwalls.com/demo/
I tried using redirects but then it ends up in too many redirects.
[
{
"Condition": {
"KeyPrefixEquals": "demo/"
},
"Redirect": {
"ReplaceKeyPrefixWith": "demo"
}
}
]
Please advice !
Related
I'm rewriting a Flask application to use NGINX Unit and I am now trying to configure static resources. However I'm using flask blueprints and the folder structure is different from what NGINX Unit expects:
{
"match": {
"uri": "/static/my-module/*"
},
"action": {
"share": "/app/myapp/modules/my-module/static/"
}
},
Now what I would like is that everything after /static/my-module/ becomes added to the local path /app/myapp/modules/my-module/static/ like this:
/static/my-module/main.css => /app/myapp/modules/my-module/static/main.css
But what happens is:
/static/my-module/main.css => /app/myapp/modules/my-module/static/static/my-module/main.css
I don't see any way to use regex, or to set make $uri only be the matching part and not the full.
Given the size of the application it's not trivial to change local path. Now I could do exotic things like symlinking but that's a hassle to maintain.
I'm using unit:1.26.1-python3.9
This is not possible today. In the future you will be able to specify URI rewrites to reconstruct the URI to match the new layout.
For now you can mitigate the symlinking pain by using the $uri variable explicitly.
"share": "/app/myapp/modules/my-module$uri"
And
$ cd /app/myapp/modules/my-module/static
$ ln -s my-module .
I have Spartacus multi site configuration as below,
B2cStorefrontModule.withConfig({
context: {
countryLang: [
'te-te',
'ca-gn'
],
}
When entering URL https://localhost.com:4200/ca-gn, it redirects to https://localhost.com:4200/ca-gn/.
Here trailing slash getting added automatically.
I have below requirement,
If I'm entering URL https://localhost.com:4200/ca-gn it should remain at same URL.
If I'm entering URL https://localhost.com:4200/ca-gn/ it should redirects to https://localhost.com:4200/ca-gn.
It looks Spartacus default behavior.
Is there any possibilities to get this overwritten for my expected behavior?
I have an Amazon S3 REST endpoint for images and file assets. I want the S3 bucket only accessible by CloudFront and the website accessing the images (using http referrer).
This is my bucket policy so far:
{
"Version": "2008-10-17",
"Id": "PolicyForCloudFrontPrivateContent",
"Statement": [
{
"Sid": "1",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity XXXXXXXXXXXX"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::<DOMAIN>/*",
"Condition":{
"StringLike":{"aws:Referer":["http://<DOMAIN>/*"]}
}
}
]
}
But once I apply the policy, the images are not accessible on the website.
Is this possible to do?
CloudFront strips Referer header by default so S3 will not see it.
https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/RequestAndResponseBehaviorCustomOrigin.html
You need to Whitelist the Referer header in CloudFront and invalidate the cache to see if it works.
I went about this a little bit differently instead of a whitelist. The method below only allows CloudFront to access the content and then you put firewall rules on CloudFront that only your website (refer) can access the cached content.
For the bucket policy, I blocked all access and cleared out the Bucket policy JSON:
In Cloudfront, create a Origins and Origin Group Policy:
Then choose your Bucket from the list in Origin Domain Name
Origin Path I left blank and Enable Origin Shield I left as no.
Restrict Bucket Access: Choose Yes
Choose Create a New Identity
Grant Read Permissions on Bucket: Yes or Create (This will update the block policy on the S3 bucket to allow only the CloudFront to get the content.
Everything else I left to default and saved.
Now to make sure I restricted the refer from my website, I went the AWS WAF Service.
From here I went to Regex pattern sets on the left menu:
Click on create regex pattern.
Name: I put DomainAccess_Only
Description: Use Waterever
Region: Important, choose Global (Cloudfront)
For the regular expressions, I put .+ and click create regex pattern set
Web ACL Details:
Name: Whatever you want, leave metric default
Resource type: CloudFront distributions
Add AWS Resources, click it and check your cloudfront domain and add it (click next)
Next Choose Rule builder
Choose whatever name for your rule and choose Regular rule
Then choose If a request Matches the statement (unless you have more than one domain)
Inspect: Header
Header field name: referrer
Match type: Starts with string
String to match: https://yourdomain.com (this needs to be exactly what your domain is)
Scroll down and choose Action: allow
Then Add rule
Once you have done that, make rule to go to Rules, and make sure the default rule is to Block.
If it's not set to block, click edit and change it.
Now your content can only be accessed by your website through cloudfront. Hotlink and Direct access to images will not work unless it's coming from your website.
How can I host the AASA file on the same domain where the CNAME redirects to thirdparty.bnc.lt ? Trying to download the AASA will just always redirect to thirdparty.bnc.lt, won't it?
Here's where I'm stuck:
1. Begin setup of Sendgrid email integration
2. Step 2 (Configure ESP): put in the correct info (see pic)
Get these errors (although notice the CNAME is happy):
How can the AASA ever be found/valid when the click tracking domain redirects to thirdparty.bnc.lt
It could be because the AASA file hosted on your domain is incorrectly formatted. Here is a sample AASA file contents for your reference:
{
"applinks": {
"apps": [],
"details": [
{
"appID": "3XXXXX9M83.io.branch-labs.Branchster",
"paths": [ "NOT /e/*", "*", "/", “/archives/201?/* ]
}
]
}
}
Hope this helps. Please check out our blog to know more about AASA files.
If you have already tried this and still facing issue let us know or write to us at integrations#branch.io and we'll be happy to provide you with the required support!
I'm having some difficulties setting up static website hosting using Amazon S3 and Cloudfront.
We have many websites that we would like to serve as static websites using Amazon S3 + Cloudfront and we would prefer to host them all in a single S3 bucket.
Initial setup is pretty straight forward but we are having issues with sub-folder redirects if omitting trailing slash in the URL.
example, setting up a single website from the bucket:
bucket contents for website1:
s3://bucket-name/websites/website1/index.html
s3://bucket-name/websites/website1/about/index.html
I have enabled static website hosting for this bucket with default document set to 'index.html'
I have created a Cloudfront web distribution to serve this single website, default root object is set to 'index.html'.
The distribution has a custom origin pointing to the static website url 'bucket-name.s3-website-us-east-1.amazonaws.com' with Origin Path set to '/websites/website1'
When navigating to the distribution url 'http://example.cloudfront.net' it correctly serves the 'index.html' document from 's3://bucket-name/websites/website1/index.html'
When navigating to 'http://example.cloudfront.net/about/' it also correctly serves the 'index.html' document from 's3://bucket-name/websites/website1/about/index.html'
But, if I omit the trailing slash like 'http://example.cloudfront.net/about' S3 redirects me to 'http://example.cloudfront.net/websites/website1/about/', since I have Origin Path set to '/websites/website1' Cloudfront will request index.html from 's3://bucket-name/websites/website1/about/websites/website1/about/index.html' which does not exist.
Am I missing something here? Is this an impossible setup using only Cloudfront and S3?
I ended up solving it by using routing rules for the S3 bucket
https://docs.aws.amazon.com/AmazonS3/latest/dev/how-to-page-redirect.html
the problem is the redirect caused by omitting a trailing slash results in the Orgigin Path being appended to the full S3 bucket path ("example.cloudfront.net/about" redirects to "example.cloudfront.net/websites/website1/websites/website1/about/" that fails because the path is invalid)
The below routing rule solves this by triggering on the faulty path pattern prefix and redirecting back to the Cloudfront distribution with the prefix stripped from the request, i.e ("example.cloudfront.net/about" redirects to "example.cloudfront.net/websites/website1/websites/website1/about/" that redirects to "example.cloudfront.net/about/")
The downside is that you need to remember to modify the routing rules when adding new distributions
<RoutingRules>
<RoutingRule>
<Condition>
<KeyPrefixEquals>websites/website1/websites/website1/</KeyPrefixEquals>
</Condition>
<Redirect>
<HostName>example.cloudfront.net</HostName>
<ReplaceKeyPrefixWith></ReplaceKeyPrefixWith>
</Redirect>
</RoutingRule>
</RoutingRules>