Search code examples
apacheurl.htaccessapache2backslash

Can't Add Slash with .htaccess


I have a site with some html files on it. One of them is contact.html. This is my .htaccess, and I'm having problems where I can address the page with site.com/contact, but not site.com/contact/. (Note ending slash.) What's the fix?

RewriteEngine On

# If the requested URI does not contain a period in the final path-part
RewriteCond %{REQUEST_URI} !(\.[^./]+)$
# and if it does not exist as a directory
RewriteCond %{REQUEST_fileNAME} !-d
# and if it does not exist as a file
RewriteCond %{REQUEST_fileNAME} !-f
# then add .html to get the actual filename
rewriterule (.*) /$1.html [L]

Solution

  • Instead of:

    rewriterule (.*) /$1.html [L]
    

    Try:

    RewriteRule ^([^/]*)/?$ /$1.html [L]