【发布时间】:2015-06-08 22:22:20
【问题描述】:
我的 .htaccess 文件没有被读取,我在 /var/www/html 中放了一个 .htaccess 文件,其中包含
Header add Access-Control-Allow-Origin "*"
Header add Access-Control-Allow-Headers "origin, x-requested-with, content-type"
Header add Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"
然后我的 http.conf 文件看起来像这样
ServerRoot "/etc/httpd"
<Directory />
AllowOverride none
Require all denied
</Directory>
DocumentRoot "/var/www/html"
<Directory "/var/www">
AllowOverride None
# Allow open access:
Require all granted
</Directory>
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
<Directory "/var/www/cgi-bin">
AllowOverride None
Options None
Require all granted
</Directory>
我要访问的文件位于我的 /var/www/html 文件夹中,但是当我尝试从另一台服务器访问它时,我不断收到此错误
Image from origin 'http://serverB' has been blocked from loading by Cross-Origin Resource Sharing policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://example.com' is therefore not allowed access.
为什么我的 .htacces 没有被读取,我怎样才能让它被读取?
谢谢
【问题讨论】:
-
ls -l会显示文件的权限,也许会有线索。 -
@ESYSCODER 这列出了我根目录中文件的权限我不确定这有什么帮助?
-
我在想你会把它的结果添加到答案中。 .htaccess 的权限是否允许 apache 读取它?用户/组匹配apache进程用户/组?
-
@ESYSCODER 我的 .htaccess 文件位于
/var/www/html而不是/root并且.htaccess文件的所有者和组是未知的,我需要将其设置为 apache 吗? -
Apache 必须能够读取它,在
/var/www/html执行chmod 0644 .htaccess以允许所有人读取它或将用户更改为apache 用户。