[英]How to conditionally redirect to a custom scheme URL in Apache?
I have an Apache configured like this: 我有一个像这样配置的Apache:
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/launchApp$
RewriteCond %{HTTP_USER_AGENT} Android
# Here I want to redirect to an URL with a custom scheme
The RewriteRule
does not work form custom schemes (in my case mobile://...
) RewriteRule
不适用于自定义方案(在我的情况下是mobile://...
)
The PHP module is loaded in my Apache, then I thought about a solution like redirecting to a local URL serving a file like: PHP模块加载到我的Apache中,然后我想到了一个解决方案,比如重定向到服务于以下文件的本地URL:
<?php
header("Location: mobile://...");
?>
But I don't like the idea of achieving this by forwading the HTTP request to a local one, and it causes problems with the rest of my configuration. 但是我不喜欢通过将HTTP请求转发到本地请求来实现这一点的想法,并且它会导致我的其余配置出现问题。
How to conditionally redirect to a custom scheme URL in Apache? 如何在Apache中有条件地重定向到自定义方案URL?
I found a satisfying solution, which uses a shell script and allows not to proxy the request, by referring directly to a filesystem path: 我找到了一个令人满意的解决方案,它使用shell脚本并允许不通过直接引用文件系统路径来代理请求:
I've created the file /var/www/cgi-bin/redirectToMobile.sh
: 我创建了文件
/var/www/cgi-bin/redirectToMobile.sh
:
#!/bin/sh -f
echo "Status: 302 Found"
echo "Location: mobile://..."
echo ""
And then the following Apache conf: 然后是以下Apache conf:
RewriteCond %{REQUEST_URI} ^/launchApp$
RewriteCond %{HTTP_USER_AGENT} Android
RewriteRule ^.*$ /var/www/cgi-bin/redirectToMobile.sh [L]
ScriptAlias /cgi-bin/ /var/www/cgi-bin/
<Directory "/var/www/cgi-bin">
AddHandler cgi-script .sh
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.