rcjsdev
rcjsdev

Reputation: 843

Inject HTML into nginx rewrite

I'm wanting to inject some HTML into a webpage when a user hits /redirected and show the rest of the page as normal. At the moment these directives are just showing the normal index.html without the injected HTML. Is there a way to do this?

server {
  server_name example.com default_server;
  root /var/www/website/dist/;

  location ~* /redirected$ {
    sub_filter "<body class=\"dark-text\">" "<body><div>You have been redirected here</div>";
    sub_filter_once on;
    rewrite ^/redirected$ /index.html;
  }
}

Upvotes: 0

Views: 564

Answers (1)

Tarun Lalwani
Tarun Lalwani

Reputation: 146630

Try changing rewrite ^/redirected$ /index.html; to try_files /index.html;.

Basically you don't want to redirect but you want to show the file

Upvotes: 1

Related Questions