2017-02-04 19 views
0

am buyildiung一个angular2应用程序并托管php共享主机上的后端。 每当我发送POST请求我得到的在htaccess中启用apache headers_module

No 'Access-Control-Allow-Origin' header is present on the requested resource 

错误在我的本地XAMPP我不得不启用headers_module在Apache来解决这个,我已经联系了共享的托管公司,但他们不能使模块

我该如何去解决这个可能是在.htaccess文件

这是当前.htaccess文件

RewriteEngine on 

# hide files and folders 
RedirectMatch 404 /_protected 
    RedirectMatch 404 /\.git 
RedirectMatch 404 /composer\. 
RedirectMatch 404 /.bowerrc 

# If a directory or a file exists, use the request directly 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
# Otherwise forward the request to index.php 
RewriteRule . index.php 
Header set Access-Control-Allow-Origin "*" 
Header set Access-Control-Allow-Headers "Content-Type" 

w ^帽子我是否需要在上面的.htaccess文件添加到作为一个四处为这个错误,甚至作为旁路的

headers_module 

回答

0

不,你不能使用.htaccess加载的模块。该LoadModule directive背景是:

server config, virtual host 

但你并不需要依赖于服务器的配置,PHP可以生成HTTP头就好了:

header('Access-Control-Allow-Origin: *'); 

reference

当然, Yii有一个builtin mechanism to generate HTTP headers

+0

我也在yii2中设置了标题,但仍然返回错误,请求的资源上没有'Access-Control-Allow-Origin'标题 –