简体   繁体   English

下游404上的Apache重定向

[英]Apache Redirect on downstream 404

We are building a mobile site whose url structure matches our current desktop site. 我们正在构建一个其网址结构与我们当前的桌面网站匹配的移动网站。 We are hosting them on the same domain, and using apache to filter traffic between them using WURFL to help decide which agents go where. 我们将它们托管在同一个域中,并使用apache使用WURFL来过滤它们之间的流量,以帮助确定哪些代理去哪里。

Our filtering rules currently look like this: 目前,我们的过滤规则如下所示:

RewriteCond %{HTTP_COOKIE} "bucket=mobile"
RewriteRule ^(.*)$ http://internal-mobile-pool.ourdomain.com/$1 [P]

RewriteRule ^(.*)$ http://internal-desktop-pool.ourdomain.com/$1 [P]

Our WURFL based solution sets the 'bucket' cookie for us. 我们基于WURFL的解决方案为我们设置了“存储桶” cookie。

The problem we are facing is that not all the urls on our desktop site have been re-implemented on our mobile site. 我们面临的问题是,并非我们的桌面网站上的所有网址都已在我们的移动网站上重新实现。 What I would ideally like, is for the above rule to apply, but if it tries to go to the mobile servers, and gets a 404, it serves up the content from the desktop servers instead. 我理想的情况是应用上述规则,但是如果它尝试转到移动服务器并获取404,它将代替桌面服务器提供内容。

ie If a mobile requests www.ourdomain.com/some_desktop_only_resource.html, and the internal-mobile-pool.ourdomain.com/some_desktop_only_resource.html returns a 404 - for it to return the content on desktop-pool.ourdomain.com/some_desktop_only_resource.html 例如,如果移动设备请求www.ourdomain.com/some_desktop_only_resource.html,并且internal-mobile-pool.ourdomain.com/some_desktop_only_resource.html返回404,则该404返回其在desktop-pool.ourdomain.com/some_desktop_only_resource上的内容.html

To describe this in pseudo-code 用伪代码描述

if(isMobile)
   response = getMobileResponse(url)
   if(response.code != 404)
        serveResponse(response)
   else
        serveResponse(getDesktopResponse(url))

I know this is possible if I list all the supported urls in this file - I would like to avoid this, as I would like this Platform Recognition layer to be independent of the application it serves. 我知道如果在此文件中列出所有受支持的url,这是可能的-我想避免这种情况,因为我希望该Platform Recognition层独立于它所服务的应用程序。 I also know I could solve this in the mobile application itself by redirecting from there, but if at all possible, I would like this Platform Recognition layer to be self-contained. 我也知道我可以通过从那里重定向来解决移动应用程序本身中的问题,但如果有可能,我希望此平台识别层是独立的。

Is this possible using mod_rewrite? 使用mod_rewrite是否可以?

Don't think there's a way to do this using mod_rewrite. 不要以为有一种使用mod_rewrite的方法。 Because you're using the [P] flag to proxy, the RewriteRule hands the proxy request to mod_proxy and doesn't even know if it went through or not. 因为您使用[P]标志进行代理,所以RewriteRule将代理请求移交给mod_proxy,甚至不知道请求是否通过。 If everything was in the same document root (or at least subdirectories of the document root), you'd be able to use the -f conditional check to see if a file exists. 如果所有内容都在同一文档根目录中(或至少在文档根目录的子目录中),则可以使用-f条件检查来查看文件是否存在。

Something you could try doing, though I have no idea if this will work, is using mod_proxy's ProxyErrorOverride along with ErrorDocument . 尽管我不知道这是否行得通,但您可以尝试使用mod_proxy的ProxyErrorOverrideErrorDocument If your ProxyErrorOverride is turned on, theoretically if a proxied request returns an error, mod_proxy will use the local error handler instead of the proxied one. 如果您的ProxyErrorOverride处于打开状态,则理论上如果代理请求返回错误,mod_proxy将使用本地错误处理程序,而不是代理错误处理程序。 You could then use a ErrorDocument 404 to handle the proxied 404 with a php script or something, then do something about re-routing it back through the local rewrite engine (with maybe a redirect with a special query string param?) so that it could be proxied to the desktop domain. 然后,您可以使用ErrorDocument 404使用php脚本等来处理代理的404,然后对通过本地重写引擎重新路由(可能带有特殊查询字符串参数的重定向)进行一些处理,以便可以代理到桌面域。

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

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