将 .htaccess 与 RewriteEngine 一起使用时出现 500 内部服务器错误
我在共享主机 Bounceweb 上,我正在尝试添加一些重写规则以使我的链接看起来更漂亮。
这些规则之一是使网址:http://mysite.com/upload
指向:http://mysite.com/upload.php
。我的 .htaccess 文件中有这个:
RewriteEngine on
RewriteRule ^upload$ upload.php
但它给我的只是 500 内部服务器错误。我查看了我的日志,经常出现这样的情况:
[alert] [client 81.179.29.185] /home/minecraf/public_html/.htaccess: Invalid command '\xef\xbb\xbfRewriteEngine', perhaps misspelled or defined by a module not included in the server configuration
这是否意味着我的主机不支持 .htaccess?如果他们不这样做,那就太蹩脚了。我已经尝试将 .htaccess 的权限更改为 777,但没有帮助。
谢谢!
I am on the shared host Bounceweb and I am trying to add some rewrite rules to make my links look prettier.
One of these rules is to make the url: http://mysite.com/upload
point to: http://mysite.com/upload.php
. I have this in my .htaccess file:
RewriteEngine on
RewriteRule ^upload$ upload.php
but all it's giving me is a 500 Internal Server Error. I looked at my logs and this comes up a lot:
[alert] [client 81.179.29.185] /home/minecraf/public_html/.htaccess: Invalid command '\xef\xbb\xbfRewriteEngine', perhaps misspelled or defined by a module not included in the server configuration
Does this mean my host doesn't support .htaccess? Pretty lame if they don't. I've already tried changing the permissions of .htaccess to 777 and it doesn't help.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
\xef\xbb\xbf
是三个不可见的垃圾字符(至少从 Apache 的角度来看),称为 Unicode BOM 或字节顺序标记。 Apache 认为这些字符是紧随其后的命令的一部分。这就是您在日志中看到的内容,尽管字符已转义,因此肉眼可见。\xef\xbb\xbfRewriteEngine
在您的编辑器中,特别是如果您的编辑器是记事本,请确保您保存的文件不带 BOM。这应该可以在另存为对话框或其他地方选择。
\xef\xbb\xbf
are three invisible junk characters (at least from Apache's perspective) called the Unicode BOM, or byte order mark. Apache thinks that those characters are part of the command that follows right after. This is what you see in the log, though the characters are escaped so they're visible to the naked eye.\xef\xbb\xbfRewriteEngine
In your editor, especially if your editor is Notepad, make sure you're saving your file without a BOM. This should be selectable in the save as dialog or elsewhere.
可能是
mod_rewrite
模块未加载。Windows xampp :打开
xampp/apache/conf/httpd.conf
并取消注释 mod_rewrite 模块。Windows wamp :打开
wamp/bin/apache/Apache2.xx/conf/httpd.conf
并取消注释 mod_rewrite 模块。Ubuntu :
a2enmod 重写 &&服务apache2重新启动
或
cp /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/rewrite.load
然后重新加载 apache
It might be the
mod_rewrite
module is not loaded.Windows xampp : Open
xampp/apache/conf/httpd.conf
and uncomment mod_rewrite module.Windows wamp : Open
wamp/bin/apache/Apache2.x.x/conf/httpd.conf
and uncomment mod_rewrite module.Ubuntu :
a2enmod rewrite && service apache2 restart
or
cp /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/rewrite.load
Then reload apache
要在 unix 中删除 BOM,请使用 vi 和以下命令
: set nobomb
: wq
To remove the BOM in unix use vi and below command
: set nobomb
: wq
试试这个:
Try this:
试试这个。
try this.
我遇到了这个问题并用以下方法解决了它:
I had this problem and solved it with:
只需使用 UTF-8 编码(无 BOM)保存 .htaccess 文件并上传即可。
推荐使用Notepad++。 (就我而言,这有帮助)。
ATB
Just save your .htaccess file with UTF-8 encoding (without BOM) and upload.
Recommended to use Notepad++. (in my case that helped).
atb