Is there a way to strip the .html extension from webpages on a website running on GCP Application Load Balancer?
Normally, this:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
should do the trick.
But I can't see how something comparable can be used in the Advanced host and path rule as the rewrite mode which is the only option where this could have been possible.
Wouldn't have been an issue if it was App Engine where you can configure URL rewrites directly in the app.yaml file. Or a backend server where you can modify with the rule above to automatically rewrite URLs before serving content.
I'm probably missing something and would be grateful for your help.
Thanks
There are two possible solutions for stripping the HTML extension from webpages on a website running on GCP Application Load Balancer using the advanced host and path rule in the rewrite mode:
Solution1: URL rewrites
allows you to display URLs to external users in a format different
from the internal URLs used by your services, offering a form of URL
customization beyond just shortening.
First, create the URL map and attach it to the load balancer. After
that all requests that match the host and path rules that you
specified will be rewritten to remove the ".html" extension. To setup
URL rewrite, It is necessary to change the host and path rules,
check this Official
document
for configuring URL rewrite.
Solution2: In your GCP Console in your bucket, locate ‘example.html’ file and follow these steps:
Click the three dots at the right end of the file list.
Choose the ‘Rename’ option and change the file name to ‘example’.
Click the three dots again, then select ‘Edit metadata’.
In the form , find the ‘content-type’ field and input ‘text/html’.
Save the changes.
Now the file should be served without the .html extension.