.htaccess RewriteRule不能正常工作


.htaccess RewriteRule doesn`t work properly

我试图使用php的模块mod_rewrite来摆脱URL中的.php扩展。我有2个文件在根目录。htm access and team.php.

我的。htaccess文件包含以下代码。分别考虑每个场景。

<IfModule mod_rewrite.c>
  Options +FollowSymLinks
  RewriteEngine On
  RewriteBase /
  # Scenario 1 - http://localhost/team response with code 404
  # The requested URL /team was not found on this server.
  RewriteRule ^team$ team.php [NC]
  # Scenario 2 - http://localhost/teams successfully redirect to team.php 
  RewriteRule ^teams$ team.php [NC]
  # Scenario 3 - http://localhost/team response with code 404
  # The requested URL /team was not found on this server.
  RewriteRule ^team$ index.php [NC]
  # Scenario 4 - http://localhost/teams response with code 404
  # The requested URL /index.php was not found on this server.
  RewriteRule ^teams$ index.php [NC]
</IfModule>

这意味着只有场景2和场景4可以正常工作,并且在URL中添加了.php扩展名。场景1和场景3有什么问题?

我也试图使用更多的文件about.php,但它的行为方式与team.php相同。例如,对localhost/about的请求导致在此服务器上找不到404/about(场景1)。

我如何重写localhost/team请求来加载team.php文件?是否可能有错误的配置,缺少模块或错误的权限的东西?

正如anubhava在评论中所说:

尝试将Options行更改为:Options +FollowSymLinks -MultiViews

这解决了我的问题,现在rewriterrule完全按照预期工作