Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache mod rewrite is adding file extension automatically on mac

Me and my colleague are using apache on windows(2.4.18) and apache on mac(2.4.16). We are working on save project using SVN.

All requests, except some images are redirected to index.php using following .htaccess file.

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

When accessing "/c-panel/folder/something" from windows my path param in $_GET is exactly as it should be "/c-panel/folder/something". When accessing same url on mac path param is "/c-panel/folder/something.php". Have in mind that something.php file actually exists on both OS. So why on MAC apache is adding .php at the end, when it should not and when does it comes from?

Thanks in advance!

like image 597
Kamen Stoykov Avatar asked Nov 20 '25 11:11

Kamen Stoykov


1 Answers

That is due to MultiViews option turned on on OSX Apache. You can turn it off using this line at top of your .htaccess:

Options -MultiViews

Option MultiViews is used by Apache's content negotiation module that runs before mod_rewrite and makes Apache server match extensions of files. So /file can be in URL but it will serve /file.php.

like image 198
anubhava Avatar answered Nov 23 '25 07:11

anubhava



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!