I am making a small Web App which sends me reminders based on a URL parameter that it is passed. Currently, I have a personal domain - for argument's sake we'll call it http://somedomain.com
.
I have a subdomain set up in my DNS settings on my domain provider's website so that it redirects to a Google Apps Script published Web Application which is designed to send me the reminder. My workflow is as follows:
http://s.somedomain.com
and pass a parameter using ?
(for example http://s.somedomain.com?q=medicine
)s.somedomain.com
is set up to redirect to my Apps Script web application located at https://script.google.com/macros/s/.../exec
:function doGet(e){
GmailApp.sendEmail('MYEMAIL', 'Reminder: placeholder text', e.parameter.q);
return HtmlService.createHtmlOutput("✔️ Sent");
}
The workflow works great in so much as the redirects all work and I end up at a page that just says ✔️ Sent
.
The issue here however, is that when I go to s.somedomain.com?q=medicine
I get automatically redirected to s.somedomain.com/?q=medicine
(with a /
after the top level domain) which completely breaks the script, as the parameter is being passed to my root directory before redirect, causing the redirect to head to:
https://script.google.com/macros/s/.../exec/?q=medicine
and not:
https://script.google.com/macros/s/.../exec?q=medicine
I'm not 100% sure whether this is an issue with my DNS forward, or whether I will need to point my domain to a page and handle the parameters that way, or whether this can be done in Apps Script by trying to get the parameters after the trailing /
.
My domain provider is ionos (formerly 1and1), and my destination settings are as can be seen below, under Domains & SSL > Subdomains > s.somedomain.com > Adjust Destination > Forward Domain.
This does not work with a pure redirect as URL parameters are not passed on redirect 302.
This can be done however by using the 'Frame redirect' option available on the ionos Forward Domain page. As suggested by TheMaster, rather than pointing the frame redirect to
https://script.google.com/macros/s/.../exec
It now redirects to:
https://script.google.com/macros/s/...
I have edited my code.gs
file as the Apps Script web app is located on another domain and therefore can not be simply evaluated with HtmlService.createHtmlOutput()
:
function doGet(e){
GmailApp.sendEmail('MYEMAIL', 'Reminder: placeholder text', e.parameter.q);
return HtmlService.createTemplateFromFile('urlString').evaluate().setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
}
And I now have a urlString.html
file which contains the confirmation page:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
✔️ Sent
</body>
</html>