在Linux上使用此.htaccess获取错误500,在Windows上运行正常 [英] Getting Error 500 with this .htaccess on Linux, works fine on Windows
问题描述
我正在Windows上使用XAMPP,在Linux(Ubuntu)上使用LAMPP来在PHP中进行本地开发.我的.htaccess
文件中有此文件:
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
如您所见,我不想键入以HTML或PHP结尾的文件名扩展名.我的两个.htaccess
都包含相同的上述内容.
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.
令人惊讶的是,当我在Ubuntu上请求任何文件(或目录)(即使具有完整扩展名)时,我却得到了Error 500
.如果我删除此.htaccess
,一切都会好起来.
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.
在Windows上一切正常.
Everything is working as expected on Windows.
出什么问题了?
推荐答案
最后一行是:
[Thu Sep 06 20:14:25 2012] [alert] [client 127.0.0.1] /opt/lampp/htdocs/.htaccess: Invalid command '\xef\xbb\xbfRewriteEngine', perhaps misspelled or defined by a module not included in the server configuration
The last line is:
[Thu Sep 06 20:14:25 2012] [alert] [client 127.0.0.1] /opt/lampp/htdocs/.htaccess: Invalid command '\xef\xbb\xbfRewriteEngine', perhaps misspelled or defined by a module not included in the server configuration
这些字符(\xef\xbb\xbf
)是UTF-8和 unicode字节顺序标记. apache认为这是垃圾字符(至少在Linux上).在Windows中,此BOM用于使Windows知道该文件被编码为UTF-8,而不是默认的Windows文本文件使用的编码(我认为这是UTF-16,little endian).您只需要使用您喜欢的linux文本编辑器,然后删除这些字符即可.根据您使用的编辑器的不同,它们甚至可能不会显示,因此您可能需要执行类似的操作,例如从单词RewriteEngine
的末尾选择到行的开头,然后从选择的开头删除选择.这行,只需手动输入RewriteEngine
.
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 word RewriteEngine
to the beginning of the line, and delete selection, then, from the beginning of the line, just type RewriteEngine
by hand.
我不太确定将htaccess文件删除后将其移回Windows后无法正常工作的可能性.
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.
这篇关于在Linux上使用此.htaccess获取错误500,在Windows上运行正常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!