我有一个网站,有一个移动版本页面,因为我的网站是背后的反向代理,我需要一个条件函数,可以决定哪个版本显示给访问者。我使用Apache2.4,ProxyPass和ProxyReverse不允许在"If - Elseif“语句中,所以我尝试使用RewriteCond,因为它没有成功。
这是我的VirtualHost
<VirtualHost *:80>
ServerName MyWebsite.com
ServerAlias www.ReverseProxy/ ReverseProxy/m/
ProxyPreserveHost On
RewriteEngine On
RequestHeader set "Host" "MyWebsite.com"
#Show mobile version if visitors used mobile device
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|googlebot-mobile|iemobile|ipad|iphone|ipod|opera mobile|palmos|webos" [NC]
ProxyPass / http://MyWebsite.com:80/m/
ProxyPassReverse / http://MyWebsite.com:80/m/
#Show desktop version if not a mobile device
RewriteCond %{HTTP_USER_AGENT} "!(android|blackberry|googlebot-mobile|iemobile|ipad|iphone|ipod|opera mobile|palmos|webos)" [NC]
ProxyPass / http://MyWebsite.com:80/
ProxyPassReverse / http://MyWebsite.com:80/
</VirtualHost>使用上面的VirtualHost,我的反向代理只显示移动版本。如何解决这个问题?我需要添加/更改哪些内容才能使其工作?
发布于 2020-08-18 10:59:35
您不能从不同模块执行条件反向代理混合指令。
正确的方法是在这种情况下一直使用mod_rewrite:
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|googlebot-mobile|iemobile|ipad|iphone|ipod|opera mobile|palmos|webos" [NC]
RewriteRule ^/(.*) http://MyWebsite.com:80/m/$1 [P,L]
ProxyPassReverse / http://MyWebsite.com:80/m/请注意,这里的键是标记"P“来生成mod_rewrite代理,而不是重定向。
还请注意,您仍然必须使用ProxyPassReverse,因为该指令完全执行其他操作,即处理来自后端的重定向--首先是反向代理。
https://serverfault.com/questions/1030375
复制相似问题