无法使用.htaccess添加斜杠

时间:2009-05-21 16:42:53

标签: apache url .htaccess apache2 backslash

我的网站上有一些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 个答案:

答案 0 :(得分:1)

而不是:

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

尝试:

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

答案 1 :(得分:0)

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

在我的情况下,我会在$ 1之前删除斜线并且它有效!我非常感谢您从评论中学到很多东西。