0

I built a php site using the built in server. I experienced none of the problems I am now facing when using Apache.

Folder structure:

app -> index.php

controllers -> home.php

views -> home.php

I have Apache successfully serving the home page at "/" but any other page I visit returns a 404. Inside "index.php" is a "switch ($_SERVER['REQUEST_URI'])" statement. A visit to the URI called the controller which in turn calls the view:

switch ($_SERVER['REQUEST_URI'])
{
  case '/':
    home_controller::home();
    break;

  case '/signup':
    signup_controller::signup();
    break;
}

If I try to visit the "signup page" at "/signup" I get a 404. I'm not sure why this is the case. I don't know Apache that well but spent a lot of time trying to figure this out. Rewrite didn't fix the problem but I could have been doing it wrong. Any information would be much appreciated.

Edit 1 Modrewrite may solve the problem but it did not before. As stated I don't know Apache that well so finding the correct terminology may be tripping me up.

My PHP program takes the REQUEST_URI and has a router built in that matches on a switch statement. My logic was that any uri that goes to Apache would in turn go to PHP. I did nothing to make "/" work correctly. Not sure why I need to do something different to make "/signup" work.

Edit 2

I solved the problem.

try_files $uri /index.php$is_args$args;

I switched from Apache to Nginx and applied the line above. I was actually having two issues. The first was a database problem stopping the app from functioning correctly. The other was the line missing above.

This question was not a duplicate as "pretty urls" was not the answer. The problem was how Apache was routing my already made urls in php.

Thanks ippi for providing the link!

user275667
  • 121
  • 7
  • Why should Apache serve anything other than a 404 for `/signup`? Have you don't anything to route that URL to your PHP program? – Quentin May 29 '18 at 21:59
  • See edit 1. I will look again more closely at the link. – user275667 May 30 '18 at 02:56
  • https://www.slimframework.com/docs/v3/start/web-servers.html (Same info as the duplicate one, but the info is more condensed I think! Aimed at slim, but works for most php router-things) – ippi May 30 '18 at 03:00
  • That helped but now I am receiving a 502 bad gateway on all URLs. I did set root path correctly and I changed fastcgi_pass to the correct php fpm sock. – user275667 May 30 '18 at 15:12

0 Answers0