0

I am looking for an NGINX rule for my website. If the user lands on my website with a URL having index.php at the end I want to redirect them to a /404 URL with a 404 status code.

for eg
http://example.com/index.php => http://example.com/404
http://example.com/abcd/index.php => http://example.com/404
http://example.com/abcd/dcba/index.php => http://example.com/404

so far I have this but this doesn't work.

location ~ index\.php$ { return 404 https://$host/404; } 
6
  • Welcome to ServerFault. Regex locations are proceed in order they appeared in the config, do you have any other regex location blocks before this one? Commented Jun 22, 2020 at 16:03
  • no, I don't at the moment. Commented Jun 22, 2020 at 18:41
  • And what you are getting now with this config? Commented Jun 22, 2020 at 18:57
  • so when i visit a page with index.php in it it fails to load anything "This site can’t be reached" with failed status Commented Jun 22, 2020 at 20:41
  • Try: return 404; error_page 404 /404; Commented Jun 23, 2020 at 8:31

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.