Vercel Redirect trailing and non trailing slash - vercel

In my vercel.json i want redirect both trailing and non trailing slash for certain URL
i tired doing
{
"source": "/docs/api/graphql/dam/overview/:path(introduction\\/?.*)",
"destination": "/developers/docs/apis/asset-management/overview",
"permanent": true
}
So what i wanted it to do was if the user goes to
/docs/api/graphql/dam/overview/introduction
or
/docs/api/graphql/dam/overview/introduction/
it should redirect to
/developers/docs/apis/asset-management/overview

Figured out a solution to handle this
{
"source": "/docs/api/graphql/dam/overview/(introduction\\/?.*)",
"destination": "/developers/docs/apis/asset-management/overview",
"permanent": true
}

Related

Which rule has priority when multiple routing rules apply for AWS S3 Static Site

I'm looking to redirect rules for an AWS S3 site. I don't see anywhere in the documentation that states which rules take priority when multiple rules might match.
Let's say I have a configuration like:
[
{
"Condition": {
"KeyPrefixEquals": "docs/foo"
},
"Redirect": {
"ReplaceKeyPrefixWith": "foo/"
}
},
{
"Condition": {
"KeyPrefixEquals": "docs/foo/bar"
},
"Redirect": {
"ReplaceKeyPrefixWith": "bar/"
}
}
]
Would a request for docs/foo/bar/baz, which object would the static site rout to and why?
Good question. It is indeed not mentioned in the doc, but after some experiments, it appears that the rule with a smaller index in the array will take the priority. I guess the S3 checks the configuration array by iterating through it in order when a request comes.
In the case of a request with the path docs/foo/bar/baz, the first routing rule matches and you are redirected to foo//bar/baz.
Hope this helps.

301 Redirect Gatsby S3 CloudFront

I am trying to apply 301 redirect with my Gatsby and S3 + Cloudfront , and so far i have no success ,
i have about 210 redirect url , i will list below my configuration .
createRedirect({
fromPath: `/old-url`,
toPath: `/new-url`,
isPermanent: true,
redirectInBrowser: true,
});
{
resolve: 'gatsby-plugin-s3',
options: {
bucketName: process.env.S3_BUCKET,
region: 'eu-west-1',
protocol: 'https',
hostname: 'stage-mydomain.de',
bucketPrefix: 'de',
generateRoutingRules: true,
generateRedirectObjectsForPermanentRedirects: true,
}
}
note that i have no plugin related to redirect inside my config ,
what i would like to accomplish is pure 301 server side redirect , i dont want JS redirect and Meta redirect because
Js will not work with JS disabled and Meta is not good for SEO .
can someone help please?
Thanks

In Angular PWA How to Cache the API request( with paramter ) dynamically instead of manually adding each and every url in ngsw-config.json

I have some API like https://api-******y?apikey=sX4&q=london, Where q=london is a parameter that will keep changing, So how can i add this URL in the list of urls in ngsw-config.json file
"dataGroups": [
{
"name": "api-performance",
"urls": [
"https://api-***************y?apikey=sX******4&q=london",
"https://api-***************y?apikey=sX******4&q=manchester",
"https://api-***************y?apikey=sX******4&q=birmingham"
],
"cacheConfig": {
"strategy": "performance",
"maxSize": 100,
"maxAge": "3d"
}
},
I have two doubts:
Instead of adding same url again and again for all different parameters like london/manchester/birmingham is there a way that i can just add the base URL without parameter and it will store the responses for all different parameters when user will search for it?
Instead of adding the URL's manually, the URL's response should be stored dynamically when the user has searched for it when he was online. I mean i will initially not add any URL in list in the ngsw-config.json file, BUT when user has requested for that url, its response automatically get stored in cache.
I got this one, Its actually a little stupid of me to think that i have to give the complete url in the ngsw-config.json file,
Actually we just can simply give the base url, we neither have to give the apiKey parameter nor any other parameter like london/manchester/birmingham, ngsw.json file in dist folder after the build, stores the url as patterns, it just matches the base url and stores all the queries with all different parameters made to that url by user. above code can re-written like below. it will work fine by caching the data for all the stores london/manchester/birmingham, whenever user searches for them.
"dataGroups": [
{
"name": "api-performance",
"urls": [
"https://api-***************y
],
"cacheConfig": {
"strategy": "performance",
"maxSize": 100,
"maxAge": "3d"
}
},

Rewriting log data

I am sending syslog data to my LogZilla server and am unable to rewrite the data using the
Event message:
{"event_type":"Threat_Event","ipv4":"172.31.100.13","hostname":"server1.something.net","source_uuid":"df4df304c3-93f2a-41f89-8dfefd-7f54bdsf5e429f","occured":"06-Aug-2019 02:38:44","severity":"Warning","threat_type":"test file","threat_name":"Eicar","scanner_id":"Real-time file system protection","engine_version":"1498036 (20190805)","object_type":"file","object_uri":"file:///home/admin/g4.txt","action_taken":"cleaned by deleting","threat_handled":true,"need_restart":false,"username":"root","processname":"/usr/bin/vi","circumstances":"Event occurred on a newly created file.","firstseen":"06-Aug-2019 02:38:44","hash":"CF8BD9DFDDFF007F75ADF4C2BE48005CEA317C62"}
Code for automatic key value detection to rewrite message above:
{
"rewrite_rules": [
{
"match": {
"field": "program",
"value": "ESServer"
},
"update": {
"message": "${event_type}, ${ipv4}"
},
"kv": {"separator": ":", "delimiter": ","
}
}
]
}
'''
I am expecting the message to be parsed so that I can setup dashboards based on various fields from the message.
LogZilla doesn't parse kv pairs within quotes, so first you'll need to strip those out. Here's a syslog-ng rule that will do that:
filter f_program {program("ESServer")};
rewrite r_quotes { subst("\"", "", value("MESSAGE") flags("global") condition( filter(f_program))); };
log {
source(s_logzilla);
rewrite (r_quotes);
#filter(f_fwdrops);
destination(d_logzilla_network);
# Uncomment line below for debug/testing of incoming events
#destination(df_debug);
#destination(d_unix_stream);
flags(flow-control,final);
};
You should create a 'rules' directory to store any custom configurations in. Save the above in that directory as syslog.conf (or any name you prefer). The copy it to the conainer and restart syslog-ng:
docker cp syslog.conf lz_syslog:/etc/logzilla/syslog-ng
docker restart lz_syslog
Now those events should have the quotes removed when they come in. Next, create a LogZilla parser rule with the following:
first_match_only: true
rewrite_rules:
- comment:
- 'Name: ESET Security Manager KV'
- 'Sample: "event_type":"Threat_Event","ipv4":"172.31.100.13","hostname":"server1.something.net","source_uuid":"df4df304c3-93f2a-41f89-8dfefd-7f54bdsf5e429f","occured":"06-Aug-2019 02:38:44","severity":"Warning","threat_type":"test file","threat_name":"Eicar","scanner_id":"Real-time file system protection","engine_version":"1498036 (20190805)","object_type":"file","object_uri":"file:///home/admin/g4.txt","action_taken":"cleaned by deleting","threat_handled":true,"need_restart":false,"username":"root","processname":"/usr/bin/vi","circumstances":"Event occurred on a newly created file.","firstseen":"06-Aug-2019 02:38:44","hash":"CF8BD9DFDDFF007F75ADF4C2BE48005CEA317C62"'
- 'Description: ESET K/V Detection and User Tag creation'
match:
field: program
op: =~
value: 'lzadmin'
kv:
delimiter: ""
separator: ":"
pair_separator: ","
tag:
ut_event_type: ${event_type}
ut_ipv4: ${ipv4}
ut_hostname: ${hostname}
Then add the rule:
logzilla rules add kv.json

htaccess rewrite rule with : in the url on windows

I'm trying to do a rewrite rule that'll allow only P00:0:R It's for a pagination system for a website.
I tried it using php, and it works fine. But how do I get something like this into a rewrite rule?
$x = 'P10:10:R';
if(pageNos($x)) {
echo 'Passed';
} else {
echo 'Failed';
}
//
function pageNos($page) {
if(preg_match('/^[P]{1}[0-9]{1,10}[:]{1}[0-9]{1,10}[:]{1}[L|R]{1}$/',$page)) {
return true;
} else {
return false;
}
}
All I get with rule is
RewriteEngine On
RewriteRule ^/?([P]{1}[0-9]{1,10}[:]{1}[0-9]{1,10}[:]{1}[L|R]{1}+)/?$ /test/index.php [NC,L]
Forbidden
You don't have permission to access /P10:2:R on this server.
You're getting forbidden error because : is not allowed in URLs by Apache on Windows. On Windows the colon is forbidden as it is used as the drive letter separator.
However do note that colon (:) is allowed as a valid character under Linux and other non-windows platforms.