什么是Options +FollowSymLinks?

43
我在电脑上使用Lamp服务器。我开始使用Laravel PHP框架。 如果我在我的.htaccess文件中使用Options +FollowSymLinks,就会收到500错误。 如果我注释掉它,我就必须在所有地址中使用index.php..例如:
 /~ytsejam/blog/public/index.php/login

我使用Arch Linux。有没有解决方法?

编辑:我通过使用虚拟主机并删除laravel文件夹中的application/config/application.php中的index.php来解决这个问题。


1
服务器日志对于500错误有什么记录? - user166390
服务器错误! 服务器遇到内部错误,无法完成您的请求。服务器可能过载或CGI脚本中存在错误。 - ytsejam
[Sat Aug 25 10:23:33 2012] [alert] [client ::1] /home/ytsejam/public_html/blog/public/.htaccess:此处不允许使用选项。 - ytsejam
3个回答

20

你可以尝试在互联网上搜索“.htaccess Options not allowed here”。

我在谷歌上找到的建议是:

检查您的httpd.conf文件是否具有AllowOverride All。

对我来说有效的.htaccess文件(放置在Laravel / public文件夹中):

# Apache configuration file
# http://httpd.apache.org/docs/2.2/mod/quickreference.html

# Turning on the rewrite engine is necessary for the following rules and
# features. "+FollowSymLinks" must be enabled for this to work symbolically.

<IfModule mod_rewrite.c>
    Options +FollowSymLinks
    RewriteEngine On
</IfModule>

# For all files not found in the file system, reroute the request to the
# "index.php" front controller, keeping the query string intact

<IfModule mod_rewrite.c>
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

希望这能对你有所帮助。否则,你可以在Laravel论坛(http://forums.laravel.com/)上提出问题,那里有一些非常乐于助人的人。


10

参数Options FollowSymLinks使您可以在网站根目录中创建一个符号链接,指向其他的文件/目录。如果禁用此选项,Apache 将拒绝跟随此类符号链接。更安全的Options SymLinksIfOwnerMatch可以替代使用,该选项只允许您链接您拥有的其他文件。

如果您在 .htaccess 中使用带有被禁止的参数的 Options 指令,则服务器将返回 HTTP 500 错误代码。

.htaccess 选项由主 Apache 配置文件的指令AllowOverride定义。要允许符号链接,则需要将此指令设置为 AllOptions

除了允许使用符号链接外,还需要该指令才能在.htaccess 上下文中启用mod_rewrite。但是,对于此用途也可以使用更安全的SymLinksIfOwnerMatch选项。


1
你知道为什么在 .htaccess 文件中需要使用 mod_rewrite 吗?我在文档中看到了这个限定词,但除了“安全原因”之外没有其他解释... - jwd
是的,这是为了安全性 - 控制用户通过.htaccess文件使用mod_rewrite。最好的情况是它有单独的参数,但也许Apache模块不能为AllowOverride引入新的参数,所以他们选择了现有的其中一个... - Marki555
1
我的问题换个说法就是:这个额外的AllowOverride要求能够防止恶意人员做什么?我不明白它实际上能为你带来什么好处... - jwd
哦!你救了我的一天。这个可用了。Options SymLinksIfOwnerMatch - arefindev

8
当你在浏览器中访问网站并浏览到/system/files/images文件夹时,服务器如何知道它应该从/pictures文件夹获取image.png?这种行为由所谓的符号链接负责。在您的系统中,有一个符号链接告诉您的服务器“如果访问者请求/system/files/images/image.png,则显示他/pictures/image.png。”
那么,FollowSymLinks设置的作用是什么?
FollowSymLinks与服务器安全有关。在处理Web服务器时,您不能将事情留在未定义状态。您必须告诉谁可以访问什么。 FollowSymLinks设置告诉您的服务器是否应该跟随符号链接。换句话说,如果我们的情况下禁用了FollowSymLinks,浏览/system/files/images/image.png文件会根据其他设置返回403(访问被禁止)或404(未找到)错误。
来源:http://www.maxi-pedia.com/FollowSymLinks

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接