我的.htaccess文件中有以下规则:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(?:\.\w+)$
RewriteRule ^func/(.*)(/.*)?$ includes/function/post/$1.php$2所以我可以去看看:
http://localhost/func/create/?ID=1
(it'll goto http://localhost/includes/function/post/create.php?ID=1)它运行得很好,但是如果我在javascript中使用EventSource,如下所示:
new EventSource('http://localhost/func/create/?ID=' + ID);然后将Accept: text/event-stream添加到请求头中,
但是我注意到响应头的内容类型是text/html; charset=iso-8859-1,
然后给我一个HTTP 406不被接受的状态代码,
(如果删除请求头中的Accept: text/event-stream,则工作正常)
我确保在我的php源代码中添加了这一行:
header('Content-Type: text/event-stream;');如果我去拜访http://localhost/includes/function/post/create.php?ID=1,
一切都很好,EventSource不支持mod_rewrite吗?
编辑-
我试过:
<FilesMatch "create.*$">
ForceType text/event-stream
</FilesMatch>但它返回HTTP 404未找到。:/
编辑2-
因此,我只是添加了一个新规则来覆盖内容类型:
RewriteRule ^.*/(.*)/create(/.*) includes/function/$1/create.php$2 [T=text/event-stream]所以任何用“创建”命名的文件都将是一个text/event-stream,
我不能将它应用于所有php文件,因为我还有其他文件
那不应该是一种text/event-stream,但现在我遇到了一个新的问题..
如果我的php出错..。它仍然会为我回复一个text/event-stream。
我会把它指出来的
发布于 2014-11-23 12:36:31
所以我得到了一个临时解决方案,强制内容类型为text/event-stream,
只需添加以下规则:
RewriteRule ^.*/(.*)/create(/.*) includes/function/$1/create.php$2 [T=text/event-stream]所以任何用“创建”命名的文件都将是一个text/event-stream,
但是它会导致另一个问题:一旦PHP出错,它仍然会为您返回text/event-stream。
https://stackoverflow.com/questions/27088105
复制相似问题