When typing in the address bar index.php it still does not redirect to index without .php . I tried on the test line - everything works fine. Where is the mistake?

 $pattern = "/\.(php|html|asp|aspx|phtml|shtml)/i"; if(preg_match($pattern, $_SERVER['REQUEST_URI'])){ $currentPage = $_SERVER['REQUEST_URI']; $shortCut = preg_replace($pattern, "", $shortCut); header("Location:".$shortCut); } 

Closed due to the fact that off-topic participants Eugen Eray , user207618, Visman , aleksandr barakin , andreymal 6 Jun '17 at 18:07 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • "The question is caused by a problem that is no longer reproduced or typed . Although similar questions may be relevant on this site, solving this question is unlikely to help future visitors. You can usually avoid similar questions by writing and researching a minimum program to reproduce the problem before publishing the question. " - Community spirit, Visman, aleksandr barakin, andreymal
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • After Location: there is no space, and after header("Location:".$shortCut); no exit(); - Visman
  • one
    And what should happen? How do you relate $currentPage and $shortCut ? - br3t
  • @ br3t I have Options +MultiViews in the server config and if the user types .php at the end of the file name, he will still be sent to the same page without .php - Eugen Eray

1 answer 1

In the preg_replace() function, you use the non-initialized variable shortCut . In the line $shortCut = preg_replace($pattern, "", $shortCut);

Probably you meant $shortCut = preg_replace($pattern, "", $currentPage);

  • Thanks, I'm an idiot. Himself would put a minus. - Eugen Eray