Mobile app version of vmapp.org
Login or Join
XinRu657

: My website keeps redirect to the "index.php" account on Instagram app My htaccess code allows example.com/username redirect to any username on Instagram app. But when I open example.com it redirects

@XinRu657

Posted in: #Deeplinks #Htaccess #Redirects

My htaccess code allows example.com/username redirect to any username on Instagram app. But when I open example.com it redirects to an Instagram account called index.php.
How can I fix it?
Here is my htaccess

RedirectMatch 302 /(.+) instagram://user?username=

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @XinRu657

1 Comments

Sorted by latest first Latest Oldest Best

 

@Jamie184

This is probably due to mod_dir issuing a subrequest for the directory index (ie. index.php).

You can try adding a negative lookahead to the regex to specifically exclude requests for index.php. For example:

RedirectMatch 302 /(?!index.php)(.+) instagram://user?username=


UPDATE: If you are now having a problem with index.html (another possible directory index) then you can exclude this as well:

RedirectMatch 302 /(?!index.php|index.html)(.+) instagram://user?username=


Or disable directory indexes altogether and redirect everything (change .+ to .*). For example:

DirectoryIndex disabled
RedirectMatch 302 /(.*) instagram://user?username=


However, this will redirect even when no username is given.



To avoid conflicts with your existing site, it would probably be preferable to make this "instagram" URL unique, so it doesn't override your existing URLs. For example: example.com/instagram/<username>. You could then simplify the above directive to:

RedirectMatch 302 /instagram/(.+) instagram://user?username=


Or, you could even reduce it to something like example.com/i/<username> - if that is still unique.

RedirectMatch 302 /i/(.+) instagram://user?username=

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme