简体   繁体   English

从iphone / ipad应用程序RewriteCond

[英]RewriteCond from iphone/ipad application

In my apache, the config file looks like this: 在我的apache中,配置文件如下所示:

RewriteCond %{HTTP_REFERER} !^mysite.com [NC]

I build an iphone and ipad application and inside I put a safari browser. 我建立了一个iphone和ipad应用程序,在里面我放了一个safari浏览器。

How can I allow the safari browser of the application (only the application that I created) to access the image? 如何允许应用程序的Safari浏览器(仅限我创建的应用程序)访问图像?

If you are using iOS UIWebView this could be a solution: 如果您使用的是iOS UIWebView,这可能是一个解决方案:

You change the default user agent (here we are changing it to "UniqueAppUserAgent") sent by WebView by running this code once when your app starts 您可以通过在应用启动时运行此代码更改WebView发送的默认用户代理(此处我们将其更改为“UniqueAppUserAgent”)

NSDictionary *dictionnary = [NSDictionary dictionaryWithObjectsAndKeys:@"UniqueAppUserAgent", @"UserAgent", nil];
[[NSUserDefaults standardUserDefaults] registerDefaults:dictionnary];  

Then use the %{HTTP_USER_AGENT} as your condition 然后使用%{HTTP_USER_AGENT}作为条件

RewriteCond %{HTTP_USER_AGENT} UniqueAppUserAgent

If I understand correctly what you are trying to do, you would like to send a request out of your app and specify an HTTP_REFERER so that your apache rule is activated. 如果我正确理解您要执行的操作,您希望从应用程序中发送请求并指定HTTP_REFERER,以便激活您的apache规则。

You can do this by splitting the HTTP request to your server and the displaying of the HTML inside of your app. 您可以通过将HTTP请求拆分到服务器并在应用程序内部显示HTML来实现此目的。 Ie, 也就是说,

  1. get the HTML out of your server by using an NSURLConnection ; 使用NSURLConnection从服务器中获取HTML; you can find many examples of using it on the web, here I want just to point out that you can specify a custom header for your request like this: 你可以在网上找到许多使用它的例子,在这里我只想指出你可以为你的请求指定一个自定义标题,如下所示:

      NSMutableURLRequest* request = [[[NSMutableURLRequest alloc] initWithURL:url] autorelease]; [request setValue:@"mySite.com" forHTTPHeaderField:@"HTTP_REFERER"]; 
  2. once, you get the HTML from your request, you load it in your UIWebView by using - (void)loadHTMLString:(NSString *)string baseURL:(NSURL *)baseURL : 一旦你从你的请求中获得HTML,你可以使用- (void)loadHTMLString:(NSString *)string baseURL:(NSURL *)baseURL它加载到你的UIWebView中:

     [webView loadHTMLString:myHtml baseURL:nil]; 

If you provide the code you have, in any case, it will be easier to help. 如果您提供您拥有的代码,无论如何,它将更容易提供帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM