我和我的同事在Windows(2.4.18)和Mac(2.4.16)上都使用apache。我们正在使用SVN保存项目。

使用以下.htaccess文件将除某些图像以外的所有请求重定向到index.php。

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !index.php
RewriteCond %{REQUEST_FILENAME} !(\.png|\.jpg|\.gif|\.jpeg|\.bmp|\.woff2)$
RewriteRule ^([^?]*)$ /index.php?path=$1 [NC,L,QSA]

从Windows访问“/ c-panel / folder / something”时,$ _ GET中的路径参数与“/ c-panel / folder / something”完全相同。在Mac路径上访问相同的URL时,参数为“/c-panel/folder/something.php”。请记住,这两个操作系统上都存在something.php文件。那么,为什么在MAC上apache在末尾添加.php,何时不应该添加它以及它何时来自?

提前致谢!

最佳答案

这是由于在OSX Apache上启用了MultiViews选项。您可以使用.htaccess顶部的以下行将其关闭:

Options -MultiViews

选项MultiViewsApache's content negotiation module使用,后者在 mod_rewrite之前运行,并使Apache服务器匹配文件扩展名。因此/file可以在URL中,但它将提供/file.php

07-27 18:38