Redirect to page without needing .html in link

Right now I have to go to “https://trapeezee.bss.design/support.html

and i’d like it to go there with just “https://trapeezee.bss.design/support

Can this be done in BSS ?

Unfortunately not, although I’d suggest posting this as a suggestion in the Ideas category

Create a subfolder called support, then rename your support page to https://trapeezee.bss.design/support/index.html then you will be able to access it via https://trapeezee.bss.design/support

1 Like

Brilliant, never thought of that one… thanks!!

1 Like

Hmmm, this works inside Martins captured environment (Published or Previewed), but not on my web server… it seems to have moved the root down to /setup folder, so it finds the index.html in /setup, but can’t find the assets, as it’s looking for them under /setup/assets… (See Screenshot)… any suggestions?

(Sorry, my original question used /support as example, and this is switched to /setup, but exactly same thing)

@martin did you quietly know this was going to happen? If so, is there a fix? THANKS!!!

If you’re using your own server then change the htaccess file:

RewriteEngine on


RewriteCond %{THE_REQUEST} /([^.]+)\.html [NC]
RewriteRule ^ /%1 [NC,L,R]

RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [NC,L]

Then use your normal www.example.com/setup.html

This will strip the extension making it www.example.com/setup

1 Like

How about with Nginx ?
Thanks

In Nginx, you can achieve the equivalent behavior of the Apache RewriteRule and RewriteCond directives using the rewrite directive. Here’s how you can translate
@richards provided Apache rules into Nginx configuration:

Explanation of the Rules

  1. Rule 1: Redirect requests for .html URLs to the URL without the .html extension.
  2. Rule 2: Internally rewrite URLs without a .html extension to serve the corresponding .html file if it exists.

Nginx Equivalent

Add the following configuration to your Nginx server block:

server {
    listen 80;
    server_name example.com; # Replace with your domain

    root /path/to/your/document/root; # Replace with your actual document root
    index index.html;

    # Rule 1: Redirect requests ending in `.html` to the URL without `.html`
    rewrite ^/(.+)\.html$ /$1 permanent;

    # Rule 2: Internally rewrite URLs to add `.html` if the file exists
    location / {
        try_files $uri $uri.html $uri/ =404;
    }
}

Explanation of the Nginx Configuration

  1. Rule 1:

    rewrite ^/(.+)\.html$ /$1 permanent;
    

    This captures any URL ending with .html and redirects it to the same URL without the .html extension using a permanent (301) redirect.

  2. Rule 2:

    location / {
        try_files $uri $uri.html $uri/ =404;
    }
    

    This tries the following in order:

    • Serve the requested file as-is ($uri).
    • Serve the file with a .html extension ($uri.html).
    • Serve a directory index ($uri/).
    • Return a 404 error if none of the above exists.

Steps to Apply

  1. Edit your Nginx configuration file (e.g., /etc/nginx/sites-available/example.com).
  2. Add or update the server block as shown above.
  3. Test the configuration:
    sudo nginx -t
    
    Ensure there are no errors.
  4. Reload Nginx to apply the changes:
    sudo systemctl reload nginx
    

After this, your Nginx server will perform the same functionality as the Apache rewrite rules.

2 Likes

Wow, thanks so much guys!
@kuligaposten thats a great Nginx explanation.
I’ve read about the rewrite and try_files Directives, but never needed to use.
I’ll be trying in next day or two.
Fred

I guess it would be nice for this functionality to be supported inside BSS, so we could use bss.design it for an emergency backup and test site without having to modify anything on the server end (@martin hint hint?)

@martin is there any reason you couldn’t just easily add the same rewrites into your encapsulated environments?

Then both the bss.design/publish and exports would work the same!

How do you guys handle redirection to external website?

Thanks Very Much! This works… however… Nginx path is case sensitive (on Linux droplet/VPS). So it will pick up XYZ.com/test but not XYZ.com/Test… How do you handle this? (or do you)? I’m reading I need Lua or Perl, etc… can’t really find a good full how-to to do it.

try this

server {
    listen 80;
    server_name example.com; # Replace with your domain

     # Replace with your actual document root
    root /path/to/your/document/root;
    index index.html;

    # Rule: Redirect requests for any `.html` file 
    # to the same URL without `.html`
    rewrite ^/(.*)\.html$ /$1 permanent;

    # Rule: Internally rewrite URLs to add `.html` if the file exists
    location / {
        try_files $uri $uri.html $uri/ =404;
    }
}

Explanation:

  1. Rewrite Rule:

    • rewrite ^/(.*)\.html$ /$1 permanent;
      • This rule strips the .html extension for any file, regardless of whether the filename is lowercase or has uppercase letters. It matches any .html file and permanently redirects to the same path without the .html extension.
      • For example:
        • example.com/test.html will be redirected to example.com/test
        • example.com/Test.html will be redirected to example.com/Test
  2. try_files Directive:

    • The try_files directive is used to resolve the path for internal requests:
      • It first checks if the requested URI exists exactly ($uri).
      • Then it tries to resolve the URI by appending .html ($uri.html).
      • Finally, it checks if the URI is a directory ($uri/).
      • If none of these exist, it returns a 404.

Example Behavior:

  • example.com/test.html → Redirects to example.com/test (no .html).
  • example.com/Test.html → Redirects to example.com/Test (no .html).
  • example.com/other.html → Redirects to example.com/other (no .html).
  • example.com/test → Resolves to test.html internally, if the file exists.
  • example.com/Test → Resolves to Test.html internally, if the file exists

Thanks Very Much! This works… however… Nginx path is case sensitive (on Linux droplet/VPS). So it will pick up XYZ.com/test but not XYZ.com/Test… How do you handle this? (or do you)? I’m reading I need Lua or Perl, etc… can’t really find a good full how-to to do it. If I don’t trap the uppercase users (eg converting all to lowercase), I may miss some users / customers…

Here is a post how to do it with Lua or with a php script

1 Like