I have an Apache configured like this:
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://...
)
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
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.
How to conditionally redirect to a custom scheme URL in Apache?
I found a satisfying solution, which uses a shell script and allows not to proxy the request, by referring directly to a filesystem path:
I've created the file /var/www/cgi-bin/redirectToMobile.sh
:
#!/bin/sh -f
echo "Status: 302 Found"
echo "Location: mobile://..."
echo ""
And then the following 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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.