Skip to content Skip to sidebar Skip to footer

Use Htaccess To Redirect Url To App-specific Deep-link

I am trying to do the following: User visits URL with query parameter: http://www.example.com/?invite=1234 I then want them to be deep linked into the app on their iOS device, so t

Solution 1:

Not sure how this will work with the iOS device, but anyway...

RewriteRule ^invite/(.*)/$ app_name://$1 [NC,L]

This doesn't match the given URL. This would match a requested URL of the form example.com/invite/1234/. However, you are also matching anything - your example URL contains digits only.

The RewriteRulepattern matches against the URL-path only, you need to use a RewriteCond directive in order to match the query string. So, to match example.com/?invite=1234 (which has an empty URL-path), you would need to do something like the following instead:

RewriteCond %{QUERY_STRING} ^invite=([^&]+)
RewriteRule ^$ app_name://%1 [R,L]

The %1 backreference refers back to the last matched CondPattern.

I've also restricted the invite parameter value to at least 1 character - or do you really want to allow empty parameter values through? If the value can be only digits then you should limit the pattern to only digits. eg. ^invite=(\d+).

I've include the R flag - since this would have to be an external redirect - if it's going to work at all.

However, this may not work at all unless Apache is aware of the app_name protocol. If its not then it will simply be seen as a relative URL and result in a malformed redirect.

Post a Comment for "Use Htaccess To Redirect Url To App-specific Deep-link"