I’m using XAMPP on Windows and LAMPP on Linux (Ubuntu) to develop in PHP locally. I have this in my .htaccess file:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
As you can see I don’t want to type the extensions of filenames that end with either HTML or PHP. My both .htaccess contains same above content.
Amazingly, when I am requesting any file (or directory) on Ubuntu (even if with full extension), I’m getting Error 500. If I remove this .htaccess, everything gets well.
Everything is working as expected on Windows.
What’s the problem?
Those characters (
\xef\xbb\xbf) are the unicode byte order mark for UTF-8 and apache thinks it’s garbage characters (on linux at least). In windows, this BOM is used to let Windows know that the file is encoded as UTF-8 instead of whatever default windows text file uses (I think it’s UTF-16, little endian). You just need to go use your favorite linux text editor, and delete those characters. Depending on what editor you use, they may not even show up, so you may need to do something like “select from the end of the wordRewriteEngineto the beginning of the line, and delete selection, then, from the beginning of the line, just typeRewriteEngineby hand.There’s a chance that the htaccess file won’t work properly once you move it back to Windows after removing the BOM, I’m not really sure.