Can't add slash with .htaccess

I have a website with some html files. One of them is contact.html. This is my .htaccess and I am having problems where I can access a page with site.com/contact but not site.com/contact/. (Write down the trailing slash.) What is 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]

      

+1


a source to share


2 answers


Instead:

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

      



Try:

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

      

+1


a source


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

      



In my case, I'll remove the forward slash in front of the $ 1 and it works! I am grateful that you learned a lot from your comment.

0


a source







All Articles