Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

lemmon's avatar
Level 28

PHP For Beginners "page not found" using WampServer

I have followed the "php For Beginners" series on laracasts and I have made it to episode 15 "Make A PHP Router" and up to that point I have been using php -s localhost:8888 to spin up a server and it all works fine. Then I decided to open it up in wampserver, so I create the virtual host and I can only reach the home page. The other links give me the

Not Found

The requested URL was not found on this server.

Apache/2.4.46 (Win64) PHP/8.0.10 Server at demo Port 80

Thank you for your help ahead of time.

0 likes
20 replies
lemmon's avatar
Level 28

@MohamedTammam I believe that all that stuff is pre being able to manage the virtual hosts through the Virtual Hosts Management link, and my rewrite_module is checked. Thank you for your reply

lemmon's avatar
Level 28

To add to this: I am not using laravel we have written a router. I also realize the the router is serving up the / page but not the other pages that are listed as demo/about demo/contact

lemmon's avatar
Level 28

@Tray2

index

require 'functions.php';

require 'router.php';

router

$uri = parse_url($_SERVER['REQUEST_URI'])['path'];

$routes = [
    '/' => 'controllers/index.php',
    '/about' => 'controllers/about.php',
    '/contact' => 'controllers/contact.php'
];

function routeToController($uri, array $routes): void
{
    array_key_exists($uri, $routes) ? require $routes[$uri] : abort();
}

/**
 * @return void
 */
function abort($code=404): void
{
    http_response_code($code);
    
    require "views/{$code}.php";
    
    die();
}

routeToController($uri, $routes);
lemmon's avatar
Level 28

@Tray2 it does not make it to the router if I echo the $uri for home then die I get / but if I echo the uri for any other page it does not make it to the router.

the other links when I hover over them show demo/about and demo/contact respectively. the root dir is demo but for the index or home page the uri is only /

lemmon's avatar
Level 28

When I spin up a server with php -S localhost:8888 it all works fine, but in wamp it does not.

lemmon's avatar
Level 28

it is not getting past the index with a complex url but the / works fine.

jlrdw's avatar
jlrdw
Best Answer
Level 75

@lemmon added htaccess:

Options -Indexes
<IfModule mod_headers.c>
    RequestHeader unset Proxy
</IfModule>
<IfModule mod_rewrite.c>

	RewriteEngine On
	RewriteBase /phpb/
	RewriteRule ^(.*)$ index.php? [QSA,L]

</IfModule>

Tweaked:

<?php
//echo "hello";
define('DIR', realpath(__DIR__) . '/');
require 'functions.php';
require 'Database.php';
require 'Response.php';
require 'router.php';

echo DIR;

tweaked router

require DIR . $routes[$uri];

tweaked routes:

   '/phpb/about' => '/controllers/about.php',

Clicked About, it works, so app just needs tweaks, I used XAMPP.

phpb is folder I put project.

2 likes
lemmon's avatar
Level 28

Im sure there has to be an easier way. Laravel runs on wamp without a problem. based on the code below wamp is handling part of the process in an unorthodox way. That Laravel Routing has figured out.

# Virtual Hosts
#
<VirtualHost *:80>
  ServerName localhost
  ServerAlias localhost
  DocumentRoot "${INSTALL_DIR}/www"
  <Directory "${INSTALL_DIR}/www/">
    Options +Indexes +Includes +FollowSymLinks +MultiViews
    AllowOverride All
    Require local
  </Directory>
</VirtualHost>
#
#
#
#
#
#
#
#
#
#
lemmon's avatar
Level 28

I should spin up a server on digital ocean and see what happens there.

lemmon's avatar
Level 28

@jlrdw I added this and it worked.

<IfModule mod_rewrite.c>
    RewriteEngine On
	RewriteCond %{REQUEST_FILENAME} !-f
	RewriteCond %{REQUEST_FILENAME} !-d
	RewriteRule ^(.*)$ index.php/ [L]
</IfModule>

Thank you.

2 likes

Please or to participate in this conversation.