无法使用 .htaccess 添加斜杠
我有一个网站,上面有一些 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]
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]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
而不是:
尝试:
Instead of:
Try:
就我而言,我将删除 $1 之前的斜杠,这样就可以了! 我很高兴从您的评论中学到很多东西。
In my case, I will remove slash before $1 and it works! I'm appreciate to learn a great deal from your comment.