php 使用 .htaccess 文件时出现“内部服务器错误 500”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14116869/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"Internal Server Error 500" while using .htaccess file
提问by Kalpana Dixit
Possible Duplicate:
Internal Server Error
可能重复:
内部服务器错误
I am looking to change the URL of my website in php, so i am using .htaccess file for this but it showing me Internal Server Error 500.
我想在 php 中更改我网站的 URL,所以我为此使用了 .htaccess 文件,但它显示了Internal Server Error 500。
Can anyone please help me out how to solve the server error?
任何人都可以帮我解决服务器错误吗?
Looking for your valuable views.
寻求您的宝贵意见。
回答by Sahal
Finding out what is causing the 500 Server Error Here are some basic steps that you can use to find out what is causing the error.
找出导致 500 服务器错误的原因 以下是一些基本步骤,可用于找出导致错误的原因。
- Open the Error Logs tool, located in the Logs section of the cPanel.
- Reload the web page that is causing the error. Reload the Error Logs page.
- Search the error logs for your IP Address for any errors associated with it, your IP address is located at the top of the page.
- 打开位于 cPanel 日志部分的错误日志工具。
- 重新加载导致错误的网页。重新加载错误日志页面。
- 在错误日志中搜索与您的 IP 地址相关的任何错误,您的 IP 地址位于页面顶部。
There are 3 main reasons why you will see this error:
您会看到此错误的主要原因有 3 个:
- File or Folder Permissions.
- Bad code or syntaxes in your .htaccess.
- Improperly configured php.ini.
- 文件或文件夹权限。
- .htaccess 中的错误代码或语法。
- php.ini 配置不当。
File or Folder Permissions
文件或文件夹权限
[Sun Jun 05 12:03:22 2011] [error] [client 66.249.72.82] SoftException in Application.cpp:601: Directory "/home1/examplec/public_html" is writeable by group
[Sun Jun 05 12:03:22 2011] [error] [client 66.249.72.82] Application.cpp:601 中的 SoftException:目录“/home1/examplec/public_html”可按组写入
In this scenario, your account has a folder with an invalid permission set. To correct this, simply restore the permissions to "755" from "777." While each site can be different, the following permissions are most often the correct permissions to use:
在这种情况下,您的帐户有一个权限集无效的文件夹。要解决此问题,只需将权限从“777”恢复到“755”。虽然每个站点可能不同,但以下权限通常是要使用的正确权限:
Files - 644 CGI Scripts - 755 Directories - 755
文件 - 644 个 CGI 脚本 - 755 个目录 - 755
You can modify permissions with the File Manager, located in the Files category of the cPanel, an FTP client, or using the "chmod" command in SSH/Bash. For more information on how to change File and Folder permissions please see our Knowledge Base article Setting file and user permissions
您可以使用位于 cPanel 的文件类别中的文件管理器、FTP 客户端或使用 SSH/Bash 中的“chmod”命令修改权限。有关如何更改文件和文件夹权限的更多信息,请参阅我们的知识库文章设置文件和用户权限
Bad code or syntaxes in your .htaccess
.htaccess 中的错误代码或语法
There is a huge range of things .htaccess can do and isn't difficult to use, however if you do not enter the syntax correctly it can result in a Server 500 Error. Some common examples of what could cause an error are listed below.
.htaccess 可以做很多事情并且使用起来并不困难,但是如果您没有正确输入语法,它可能会导致服务器 500 错误。下面列出了一些可能导致错误的常见示例。
Syntax Not Closed
语法未关闭
[Sun Jun 05 12:11:38 2011] [alert] [client 66.249.72.82] /home1/examplec/public_html/.htaccess: /home1/examplec/public_html/.htaccess:3: ExampleRule/Module> was not closed.
[Sun Jun 05 12:11:38 2011] [alert] [client 66.249.72.82] /home1/examplec/public_html/.htaccess: /home1/examplec/public_html/.htaccess:3: ExampleRule/Module> 没有关闭。
Again, the solution is to simply fix the syntax, or remove it. In this case, close the ending "" directive properly and put the rules on their own line to resolve the problem.
同样,解决方案是简单地修复语法,或将其删除。在这种情况下,正确关闭结尾的 "" 指令并将规则放在自己的行上以解决问题。
These are just a few common examples that can be caused by bad .htaccess parameters. What you encounter will likely vary, however generally the error message is descriptive enough to determine an error from it without further investigation. Improperly configured php.ini ForceType
这些只是一些可能由错误的 .htaccess 参数引起的常见示例。您遇到的情况可能会有所不同,但通常错误消息的描述足以确定错误,无需进一步调查。php.ini ForceType 配置不当
When you are using files with (or without) an extension different then the normal extension for that filetype you can use ForceType in your .htaccess file to make it clear to the server how to handle that file (or all the files in the folder) (this works on servers without phpsuexec).
当您使用带有(或不带有)扩展名的文件时,您可以在 .htaccess 文件中使用 ForceType 来向服务器说明如何处理该文件(或文件夹中的所有文件) (这适用于没有 phpsuexec 的服务器)。
An example: When you have a file called 'item' (like Nucleus uses for FancyURL's) and want it to be parsed by the server as php you use the following code in your .htaccess file:
一个例子:当你有一个名为“item”的文件(就像 Nucleus 用于 FancyURL 的)并希望它被服务器解析为 php 时,你在 .htaccess 文件中使用以下代码:
ForceType application/x-httpd-php
However, because our servers use phpsuexec this will result in an internal server error. To solve this you can simply use SetHandler instead of ForceType, so your .htaccess-file becomes:
但是,因为我们的服务器使用 phpsuexec 这将导致内部服务器错误。要解决这个问题,您可以简单地使用 SetHandler 而不是 ForceType,因此您的 .htaccess 文件变为:
SetHandler application/x-httpd-php
php_value On a server without phpsuexec it is possible to use the php_value statement in a .htaccess file to change the settings of php (actually overwrite the settings from php.ini). On a sever with phpsuexec this will also result in a server error. To solve this you can use a php.ini file which you put in the same folder as where you would have put your .htaccess file. In that php.ini file you can change all the php values. You only have to put the values you want to modify in that file. By example if you want to set the short_open_tag to Off you would have used short_open_tag? = off in your .htaccess file. Using a php.ini file this results in:
php_value 在没有 phpsuexec 的服务器上,可以使用 .htaccess 文件中的 php_value 语句来更改 php 的设置(实际上是覆盖 php.ini 中的设置)。在带有 phpsuexec 的服务器上,这也会导致服务器错误。要解决这个问题,您可以使用一个 php.ini 文件,该文件与您放置 .htaccess 文件的位置相同。在该 php.ini 文件中,您可以更改所有 php 值。您只需将要修改的值放入该文件中。例如,如果您想将 short_open_tag 设置为 Off,您会使用 short_open_tag 吗?= 在您的 .htaccess 文件中关闭。使用 php.ini 文件会导致:
[PHP]
short_open_tag = Off
回答by prasobh
try to change ownership user of all files & folders.Then you must look permission of appropriate folders allowed properly.
尝试更改所有文件和文件夹的所有权用户。然后您必须查看正确允许的适当文件夹的权限。

