将 .htaccess 与 RewriteEngine 一起使用时出现 500 内部服务器错误

发布于 2024-10-24 19:30:05 字数 668 浏览 0 评论 0原文

我在共享主机 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

意犹 2024-10-31 19:30:05

\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.

烙印 2024-10-31 19:30:05

可能是 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

冰火雁神 2024-10-31 19:30:05

要在 unix 中删除 BOM,请使用 vi 和以下命令

: set nobomb

: wq

To remove the BOM in unix use vi and below command

: set nobomb

: wq

一场春暖 2024-10-31 19:30:05

试试这个:

a2enmod rewrite    
/etc/init.d/apache2 restart

Try this:

a2enmod rewrite    
/etc/init.d/apache2 restart
鼻尖触碰 2024-10-31 19:30:05
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

rewriterule ^upload$ upload.php

</IfModule>

试试这个。

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

rewriterule ^upload$ upload.php

</IfModule>

try this.

眼睛会笑 2024-10-31 19:30:05

我遇到了这个问题并用以下方法解决了它:

sudo a2enmod rewrite
sudo service apache2 restart

I had this problem and solved it with:

sudo a2enmod rewrite
sudo service apache2 restart
尸血腥色 2024-10-31 19:30:05

只需使用 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文