大网数据广告活动
网站运营与故障问答

My website keeps redirect to the "index.php" account on Instagram app

· 52CE 我爱测

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 /…

问题原文

原帖链接 · Bangladesh 71 · CC BY-SA 3.0

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=$1

已采纳解答

原帖链接 · MrWhite · CC BY-SA 3.0

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=$1

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=$1

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

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

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=$1

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

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

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2017-08-09)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。