通过htaccess进行GET和POST重定向/代理 [英] GET and POST redirect/proxy via htaccess

查看:137
本文介绍了通过htaccess进行GET和POST重定向/代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


有一个网站要求ajax提供一些Web服务Web方法.我没有它的代码.
它发送POST请求,并期望得到JSON作为答案.

我写了这个网络服务.我使用具有许多重写规则的hataccess文件.
一些规则直接或通过代理重定向客户端请求.

因此,有些保留POST请求,例如通过的请求
RewriteCond%{HTTP_REFERER} ^ http://(.*)/Bing $ [NC]
RewriteRule/ActivitiesService.asmx/GetLatest$ http://%1/ActivitiesService.asmx/GetLatestSearchActivities [NC,L,P]

还有一些我重写了queryString形式:
RewriteCond%{HTTP_REFERER} ^ http://(.*)/([0-9] +)[NC]
RewriteRule/ActivitiesService.asmx/GetLatest$ http://%1/ActivitiesService.asmx/GetLatestByActivityType?activityType =%2& type = 1& timestamp = 10000 [NC,L,R = 301]

我这样做是因为我没有找到一种向该方法动态添加附加参数的方法.
我无法将其留在POST方法中.

添加了用querySring调用的方法
[ScriptMethod(UseHttpGet = true)]

问题是当我[R]重定向而不是
代理丢失一些数据:

内容类型:application/json; charset = UTF-8变成带有``xml''的东西).

即使当我将Fiddler requestBuilder与该数据一起使用时,也是如此
我得到JSON作为响应,但其中包含错误.

我试图从另一个没有
的方法中调用一个方法 ScriptMethod(UseHttpGet = true)]并由
重定向
-一切都很好.如预期的那样获得了良好的JSON对象.

有人知道如何修改htaccess文件或Web服务API属性?
<code>
[CODE]
RewriteRule ^/Bing $ http://%{HTTP:Host} [NC,L,P]
RewriteRule ^/Zynga $ http://%{HTTP:Host} [NC,L,P]
RewriteRule ^/([[0-9] +)$ http://%{HTTP:Host} [NC,L,P]
RewriteRule ^/CT([0-9] +)$ http://%{HTTP:Host} [NC,L,P]

RewriteCond%{HTTP_REFERER} ^ http://(.*)/Bing $ [NC]
RewriteRule/ActivitiesService.asmx/GetLatest$ http://%1/ActivitiesService.asmx/GetLatestSearchActivities [NC,L,P]

RewriteCond%{HTTP_REFERER} ^ http://(.*)/Bing $ [NC]
RewriteRule/images/ConduitLive_header.png$ http://%1/images/Header_WatchItBing.png [NC,L,R = 301]

RewriteCond%{HTTP_REFERER} ^ http://(.*)/Zynga $ [NC]
RewriteRule/ActivitiesService.asmx/GetLatest$ http://%1/ActivitiesService.asmx/GetLatestZyngaActivities [NC,L,P]

RewriteCond%{HTTP_REFERER} ^ http://(.*)/([0-9] +)[NC]
RewriteRule/ActivitiesService.asmx/GetLatest$ http://%1/ActivitiesService.asmx/GetLatestByActivityType?activityType =%2& type = 1& timestamp = 10000 [NC,L,R = 301]

RewriteCond%{HTTP_REFERER} ^ http://(.*)/CT([0-9] +)[NC]
RewriteRule/ActivitiesService.asmx/GetLatest$ http://%1/ActivitiesService.asmx/GetLatestByCtid?ctid = CT%2& type = 1& timestamp = 10000 [NC,L,R = 301]
[/CODE]


感谢您的帮助!
周末愉快!

Hi,
there is a website that asks with ajax for some web-service web-methods. I don''t have its code.
It sends POST requests and expect to get JSON as an answer.

I write this web-service. I use hataccess file with many rewrite rules.
Some rules redirect client request directly or through proxy.

Thus some stays POST requests, like the ones that pass through
RewriteCond %{HTTP_REFERER} ^http://(.*)/Bing$ [NC]
RewriteRule /ActivitiesService.asmx/GetLatest$ http://%1/ActivitiesService.asmx/GetLatestSearchActivities [NC,L,P]

And some I rewrite t a queryString form:
RewriteCond %{HTTP_REFERER} ^http://(.*)/([0-9]+) [NC]
RewriteRule /ActivitiesService.asmx/GetLatest$ http://%1/ActivitiesService.asmx/GetLatestByActivityType?activityType=%2&type=1&timestamp=10000 [NC,L,R=301]

I did so because I didn''t find a way to dynamically add an additional parameter to the method.
I couldn''t leave it in POST method.

The methods that are called with querySring were added
[ScriptMethod(UseHttpGet = true)]

the thing is that when I [R] redirect instead of
proxy some data is lost:

Content-Type: application/json; charset=UTF-8 turns to something with ''xml'').

Even when I use Fiddler requestBuilder with this data
i get JSON as a response but with an error inside it.

I tried to call one method from another which doesn''t have
ScriptMethod(UseHttpGet = true)] and is redirected by

- and everthing worked fine. Got good JSON object as expected.

Someone has an idea how can I modify my htaccess file or web-service API attributes?
<code>
[CODE]
RewriteRule ^/Bing$ http://%{HTTP:Host} [NC,L,P]
RewriteRule ^/Zynga$ http://%{HTTP:Host} [NC,L,P]
RewriteRule ^/([0-9]+)$ http://%{HTTP:Host} [NC,L,P]
RewriteRule ^/CT([0-9]+)$ http://%{HTTP:Host} [NC,L,P]

RewriteCond %{HTTP_REFERER} ^http://(.*)/Bing$ [NC]
RewriteRule /ActivitiesService.asmx/GetLatest$ http://%1/ActivitiesService.asmx/GetLatestSearchActivities [NC,L,P]

RewriteCond %{HTTP_REFERER} ^http://(.*)/Bing$ [NC]
RewriteRule /images/ConduitLive_header.png$ http://%1/images/Header_WatchItBing.png [NC,L,R=301]

RewriteCond %{HTTP_REFERER} ^http://(.*)/Zynga$ [NC]
RewriteRule /ActivitiesService.asmx/GetLatest$ http://%1/ActivitiesService.asmx/GetLatestZyngaActivities [NC,L,P]

RewriteCond %{HTTP_REFERER} ^http://(.*)/([0-9]+) [NC]
RewriteRule /ActivitiesService.asmx/GetLatest$ http://%1/ActivitiesService.asmx/GetLatestByActivityType?activityType=%2&type=1&timestamp=10000 [NC,L,R=301]

RewriteCond %{HTTP_REFERER} ^http://(.*)/CT([0-9]+) [NC]
RewriteRule /ActivitiesService.asmx/GetLatest$ http://%1/ActivitiesService.asmx/GetLatestByCtid?ctid=CT%2&type=1&timestamp=10000 [NC,L,R=301]
[/CODE]


Thanks for any help !
Have a great weekend

推荐答案

[NC]
RewriteRule/ActivitiesService.asmx/GetLatest
[NC]
RewriteRule /ActivitiesService.asmx/GetLatest


http://%1/ActivitiesService.asmx/GetLatestSearchActivities [NC,L,P]

还有一些我重写了queryString形式:
RewriteCond%{HTTP_REFERER} ^ http://(.*)/([0-9] +)[NC]
RewriteRule/ActivitiesService.asmx/GetLatest
http://%1/ActivitiesService.asmx/GetLatestSearchActivities [NC,L,P]

And some I rewrite t a queryString form:
RewriteCond %{HTTP_REFERER} ^http://(.*)/([0-9]+) [NC]
RewriteRule /ActivitiesService.asmx/GetLatest


http://%1/ActivitiesService.asmx/GetLatestByActivityType?activityType =%2& type = 1& timestamp = 10000 [NC,L,R = 301]

我这样做是因为我没有找到一种向该方法动态添加附加参数的方法.
我无法将其留在POST方法中.

添加了用querySring调用的方法
[ScriptMethod(UseHttpGet = true)]

问题是当我[R]重定向而不是
代理丢失一些数据:

内容类型:application/json; charset = UTF-8变成带有``xml''的东西).

即使当我将Fiddler requestBuilder与该数据一起使用时,也是如此
我得到JSON作为响应,但其中包含错误.

我试图从另一个没有
的方法中调用一个方法 ScriptMethod(UseHttpGet = true)]并由
重定向
-一切都很好.如预期的那样获得了良好的JSON对象.

有人知道如何修改htaccess文件或Web服务API属性?
<code>
[CODE]
RewriteRule ^/Bing
http://%1/ActivitiesService.asmx/GetLatestByActivityType?activityType=%2&type=1&timestamp=10000 [NC,L,R=301]

I did so because I didn''t find a way to dynamically add an additional parameter to the method.
I couldn''t leave it in POST method.

The methods that are called with querySring were added
[ScriptMethod(UseHttpGet = true)]

the thing is that when I [R] redirect instead of
proxy some data is lost:

Content-Type: application/json; charset=UTF-8 turns to something with ''xml'').

Even when I use Fiddler requestBuilder with this data
i get JSON as a response but with an error inside it.

I tried to call one method from another which doesn''t have
ScriptMethod(UseHttpGet = true)] and is redirected by

- and everthing worked fine. Got good JSON object as expected.

Someone has an idea how can I modify my htaccess file or web-service API attributes?
<code>
[CODE]
RewriteRule ^/Bing


这篇关于通过htaccess进行GET和POST重定向/代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆