我在我的.htaccess中重写它删除PHP扩展的文件,将例如 so/question.php 的到的 so/question 。
I have the following rewrite in my .htaccess file which removes the .php extension from files, converting for example so/question.php to so/question.
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^\.]+)$ $1.php [NC,L]
不过,这也打破了默认DirectoryIndex的行为,在刚刚输入的目录将重定向到索引文件的文件夹中,例如: so/answer 的显示的 so/answer/index.php 的
只要结合上述code与的DirectoryIndex的index.php 不实现这两个结果。
Simply combining the above code with DirectoryIndex index.php does not achieve both results.
有人可以帮助我结合这两种功能,或重写code排除的index.php文件,这将达到同样的效果?
Can someone help me combine these two functions, or rewrite the code to exclude index.php files, which would achieve the same result?
推荐答案我想你只需要验证该文件存在这样的重写,这样你会离开404和DirectoryIndex的行为完好之前:
I'm thinking you just need to verify that the file exists prior to doing the rewrite, that way you'll leave 404 and directoryindex behaviours intact:
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^(.*)$ $1.php [NC,L]
(未测试)
更多推荐
删除的.php与扩展的.htaccess不破的DirectoryIndex
发布评论