I have a website that uses Apple universal links for sharing app events with others. Opening an event link on a device without the app installed should display a site that lets the user download it, but it should also keep the address the same. Reason for this is that this page will also be shown when the universal link is opened inside an app such as messenger, where it will have a label that asks the user to press "open in safari". Pressing that button must the open the initial link in safari to open the app correctly.
The website looks like this:
www.website.com/event/<event_id_wildcard>
The user will then be shown the site:
While keeping the initial link in the address bar.
I need to accomplish this using my .htaccess file, and as I do not host the server myself but rather through a webhosting service, changing any deeper settings is difficult.
I've tried to use RewriteEngine
RewriteCond
and RewriteRule
, by looking at these questions among others without any luck:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^/event/.*$
RewriteRule ^(.*)$ http://website.no/invite [P,NC,QSA]
This is a rather pressing issue and I have not had the time to understand the various flags
Redirect wildcard subdomains to subdirectory, without changing URL in address bar
How can I use htaccess to redirect paths with a wildcard character
https://gist.github.com/ScottPhillips/1721489
** Update **
Full .htaccess:
# Begin
RewriteEngine on
<Files "apple-app-site-association">
ForceType 'application/json'
</Files>
# Handle wildcard links
#RedirectMatch 301 ^/event/.*$ http://www.website.no/invite
RewriteRule ^event/[\w-]+/?$ invite [L,NC]
# Enforce SSL
# Handle non-www URLs
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^website\.no [NC]
RewriteRule ^(.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Handle www URLs
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.website\.no [NC]
RewriteRule ^(.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Handle URLs without .html extension
RewriteCond %{REQUEST_METHOD} ^(GET) [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}.html -f
RewriteRule ^(.*) $1.html [L]
# End