Search code examples
htmlwebpretty-urls

How do I redirect "website/page" to "website/page.html" when people type it in browser (pretty-url)


I recently started using a static site with godaddy.com without a cms. It's a basic website I uploaded and is only html/js/css.

When people type "website.com/page" they get 404 not found. When they type "website.com/page.html" they get the correct page.

How can I fix my site so users can simply type "website/page" and not be forced to type "website/page.html" without using php?

SOLUTION

After researching the information about .htaccess files provided by @Gijsberts (thank you), I did the following:

  1. Created a .htaccess file on server.
  2. Added the following code:

    # Remove the .html extension from html files
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([^.]+)$ $1.html [NC,L]


Solution

  • Most CMS systems have a .htaccess file what handles the redirect and the 404 errors. In CMS system they are most called "Pretty-urls". Read the links below to set up those pretty urls yourself with a static web page without a cms.