apache .htaccess 中的 DocumentRoot 导致错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/142653/
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
DocumentRoot in .htaccess is causing an error
提问by Greg Hewgill
I have DocumentRoot /var/www/test in my .htaccess file. This is causing the apache server to give me a 500 internal server error.
我的 .htaccess 文件中有 DocumentRoot /var/www/test 。这导致 apache 服务器给我一个 500 内部服务器错误。
The error log file shows: alert] [client 127.0.0.1] /var/www/.htaccess: DocumentRoot not allowed here
错误日志文件显示:alert] [client 127.0.0.1] /var/www/.htaccess: DocumentRoot not allowed here
AllowOveride All is set in my conf file.
AllowOveride All 在我的 conf 文件中设置。
Any idea why this is happening?
知道为什么会这样吗?
回答by Greg Hewgill
The DocumentRootdirective cannot appear in a .htaccessfile. Put it in httpd.confinstead.
该DocumentRoot的指令不能出现在一个.htaccess文件中。把它httpd.conf代替。
回答by Nick Sergeant
DocumentRoot should be set in your VirtualHost directive, not your .htaccess file.
DocumentRoot 应该在您的 VirtualHost 指令中设置,而不是您的 .htaccess 文件。
Any specific reason you put DocumentRoot in your .htaccess file?
您将 DocumentRoot 放在 .htaccess 文件中的任何具体原因?
回答by Dprado
You don't mention your apache version , but docs for 2.0 say that DocumentRoot is only valid for virtualhost or server config. Acording to the docs it should not be used in a .htacces
您没有提到您的 apache 版本,但 2.0 的文档说 DocumentRoot 仅对虚拟主机或服务器配置有效。根据文档,它不应在 .htacces 中使用

