.htaccess RewriteRule 还会影响其他同名文件吗?

.htaccess RewriteRule also affects other files with the same name?

我正在尝试使用以下方式重定向 http://www.domain.com/cart to http://www.domain.com/cart.php

RewriteRule cart cart.php [L]

可行,但我只是注意到它还会将名为 http://www.domain.com/images/cart.jpg 的文件重定向到同一页面。

如何避免这种情况发生?

在您的规则中使用开始和结束锚点以仅定位 /cart/cart/,如下所示:

RewriteRule ^cart/?$ cart.php [L,NC]