500从example移动到专用服务器时发生内部服务器错误


500 Internal Server Error when move from xamp to a dedicated server

基本上,我使用example 在我的个人电脑.htaccess中有这几行

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !('.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]

附加了什么?我正在使用Debian 8.4上的apache2移动到我的专用服务器服务器给了我下一个错误。为什么是追加?

内部服务器错误

服务器遇到内部错误或配置错误,无法完成您的请求。

请通过与服务器管理员联系webmaster@localhost通知他们此错误发生的时间,以及您的操作在此错误之前执行。

服务器错误日志中可能提供了有关此错误的更多信息。

听起来像是在Apache中没有启用mod_rewrite。启用:

a2enmod rewrite
service apache2 restart

由于缺少<ifModule mod_rewrite.c>构造,可能会发生这样的错误,因为可能没有安装此模块。所以,你可以添加这个条件,但请注意,它不会解决你的问题——你需要安装模块才能有重定向。

更新:

所以,现在你最好把代码改为:

<ifModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^([^/]+)/$ $1.php
  RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !('.[a-zA-Z0-9]{1,5}|/)$
  RewriteRule (.*)$ /$1/ [R=301,L]
</IfModule>

阅读有关Apache Docs 的更多信息

然后你需要切换mod_rewrite模块,你可以在这里阅读示例:如何安装Apache mod_rewrite模块它更多的是系统管理领域,而不是编程领域。