在apache中为访问控制源设置标头的位置

在apache中为访问控制源设置标头的位置,apache,.htaccess,drupal,drupal-7,Apache,.htaccess,Drupal,Drupal 7,已在web应用程序所在目录的.htaccess文件中添加/设置访问控制的标头drupal。但当使用jquery对其发出ajax请求时,控制台错误会给出以下消息: XMLHttpRequest cannot load http://localhost/drupal/get/news. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:566

已在web应用程序所在目录的.htaccess文件中添加/设置访问控制的标头drupal。但当使用jquery对其发出ajax请求时,控制台错误会给出以下消息:

XMLHttpRequest cannot load http://localhost/drupal/get/news. 
No 'Access-Control-Allow-Origin' header is present on the requested resource. 
Origin 'http://127.0.0.1:56687' is therefore not allowed access. 
.htaccess位于drupal文件夹中,标题设置如下:

  <IfModule mod_headers.c>

   Header set Access-Control-Allow-Origin "*"

    # Serve gzip compressed CSS files if they exist and the client accepts gzip.
    RewriteCond %{HTTP:Accept-encoding} gzip
    RewriteCond %{REQUEST_FILENAME}\.gz -s
    RewriteRule ^(.*)\.css $1\.css\.gz [QSA]

    # Serve gzip compressed JS files if they exist and the client accepts gzip.
    RewriteCond %{HTTP:Accept-encoding} gzip
    RewriteCond %{REQUEST_FILENAME}\.gz -s
    RewriteRule ^(.*)\.js $1\.js\.gz [QSA]

    # Serve correct content types, and prevent mod_deflate double gzip.
    RewriteRule \.css\.gz$ - [T=text/css,E=no-gzip:1]
    RewriteRule \.js\.gz$ - [T=text/javascript,E=no-gzip:1]

    <FilesMatch "(\.js\.gz|\.css\.gz)$">
      # Serve correct encoding type.
      Header set Content-Encoding gzip
      # Force proxies to cache gzipped & non-gzipped css/js files separately.
      Header append Vary Accept-Encoding
    </FilesMatch>
  </IfModule>
</IfModule>
任何帮助都将不胜感激

XMLHttpRequest cannot load http://localhost/drupal/get/news. 

上面的意思是,在Drupal CMS中,您有指向本地主机的引用。我的猜测是,您在本地构建了站点,然后迁移到了一个实时服务器,但在这样做的过程中,一些引用尚未更改。我建议你更换所有的http://localhost 在.sql文件中使用http://yourdomain.com 因为这些文件是公开的,没有其他人可以从外部网络访问您的本地主机资源。

当您正常访问页面时,访问控制Allow Origin头是否存在?如果没有,Apache中是否启用了mod_头?谢谢您的评论。我不太擅长服务器配置。我在一些搜索后添加了标题,但它似乎不起作用。