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?
我有一个网站上有一些html文件。其中之一是contact.html。这是我的.htaccess,我遇到问题,我可以使用site.com/contact解决该页面,但不能访问site.com/contact/。 (注意斜杠结束。)解决了什么?
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]
2 个解决方案
#1
Instead of:
rewriterule (.*) /$1.html [L]
Try:
RewriteRule ^([^/]*)/?$ /$1.html [L]
#2
RewriteRule ^([^/]*)/?$ $1.php [L]
In my case, I will remove slash before $1 and it works! I'm appreciate to learn a great deal from your comment.
在我的情况下,我将在1美元之前删除斜线,它的工作原理!我很感激从你的评论中学到很多东西。
#1
Instead of:
rewriterule (.*) /$1.html [L]
Try:
RewriteRule ^([^/]*)/?$ /$1.html [L]
#2
RewriteRule ^([^/]*)/?$ $1.php [L]
In my case, I will remove slash before $1 and it works! I'm appreciate to learn a great deal from your comment.
在我的情况下,我将在1美元之前删除斜线,它的工作原理!我很感激从你的评论中学到很多东西。