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

gurds91's avatar

Going through the php router video and having problem

I need help, am going through the php router video and followed all the steps. I am using wamp but ran into a problem

the index page s working but when clicking on about and contact it says not found on server.

Please help

0 likes
22 replies
LaryAI's avatar
Level 58

It sounds like you might be running into an issue with URL rewriting, which is common when using a custom PHP router on a local server like WAMP. Here's what you can do to troubleshoot and fix the issue:

  1. Enable mod_rewrite: Make sure that the mod_rewrite module is enabled in your WAMP server. You can do this by clicking on the WAMP icon in your system tray, going to the Apache modules, and ensuring that rewrite_module is checked.

  2. Create a .htaccess file: If you haven't already, you need to create a .htaccess file in the root directory of your project. This file will tell Apache to redirect all requests to your index.php file, where your router will handle them. Here's a basic example of what this file might look like:

Options -MultiViews
RewriteEngine On
RewriteBase /your_project_folder/

# Redirect all requests to index.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]

Replace /your_project_folder/ with the actual subdirectory of your project if it's located in a subdirectory of www or htdocs. If your project is directly in the www or htdocs folder, you can set RewriteBase /.

  1. AllowOverride directive: Ensure that the AllowOverride directive is set to All for your project directory in the Apache configuration file (httpd.conf). This allows .htaccess files to override the server configuration settings.
<Directory "/path/to/your/project">
    AllowOverride All
</Directory>
  1. Restart WAMP: After making these changes, restart your WAMP server to ensure that the new configuration is applied.

  2. Check your router configuration: Make sure that your router is set up to handle requests to the about and contact pages. Your index.php file should include logic to handle different URIs and direct them to the appropriate controllers or views.

If you've followed these steps and are still encountering issues, please provide more details about your router setup and any error messages you're seeing. This will help in diagnosing the problem further.

gurds91's avatar

hi, I followed advice and ran into another error:

( ! ) Fatal error: Cannot redeclare dd() (previously declared in C:\wamp64\www\tutphp\functions.php:3) in C:\wamp64\www\tutphp\functions.php on line 3 Call Stack

Time Memory Function Location

1 0.0008 362632 {main}( ) ...\index.php:0 2 0.0012 363184 require( 'C:\wamp64\www\tutphp\controllers\about.php ) ...\index.php:14

what one earth is C:\wamp64\www\tutphp\functions.php:3 , I don't even have that file path in my project, I do have C:\wamp64\www\tutphp\functions.php though.

Bogey's avatar

The '3' refers to line 3 in that file.

You need to remove require "functions.php"; from all of your files except for the index.php file

1 like
gurds91's avatar

Hi I did this but still not working:(

I already checked that require 'functions.php' was removed from all my controller files.

Bogey's avatar

@gurds91 in the video the guy didn't delete it from about.php to show the error you are getting and you're getting this error from about.php.

1 like
gurds91's avatar

@Bogey hi bogey,

I checked my three controller files: about.php , contact.php, index.php and there was no require 'functions.php' in any of them.

Still doesn't work :(

gurds91's avatar

@jlrdw hi , I looked at this but I am still lost ;(

is all that code you inputted into just the .htaccess file created in root of project?

What is the response.php and router.php? Thanks , completely lost with that.

jlrdw's avatar

@gurds91 goes in public, And you need a virtual host setup. Jeffrey is Using the php built in server.

Google Setting up a virtual host for apache. There are a lot of examples out there.

1 like
Bogey's avatar

@jlrdw It all works for me in xampp without setting any virtual hosts.

Just delete all instances of dd()

gurds91's avatar

@Bogey xampp already has php installed. Which virtual server do you need. Can someone help me with the .htaccess file

Is that all you need to add to get it working xampp?

gurds91's avatar

@jlrdw where do you put this:

still finding it very unclear, could you help me here with step by step instructions on how to solve. Still lost ;(

gurds91's avatar

@Shivamyadav

on http://localhost/tutphp/about I get error:

( ! ) Fatal error: Cannot redeclare urlIs() (previously declared in C:\wamp64\www\tutphp\functions.php:4) in C:\wamp64\www\tutphp\functions.php on line 4 Call Stack

Time Memory Function Location

1 0.0017 362632 {main}( ) ...\index.php:0 2 0.0072 362944 require( 'C:\wamp64\www\tutphp\controllers\about.php ) ...\index.php:14

on localhost/tutphp/contact I get error:

! ) Fatal error: Cannot redeclare urlIs() (previously declared in C:\wamp64\www\tutphp\functions.php:4) in C:\wamp64\www\tutphp\functions.php on line 4 Call Stack

Time Memory Function Location

1 0.0014 362424 {main}( ) ...\index.php:0 2 0.0042 362976 require( 'C:\wamp64\www\tutphp\controllers\contact.php ) ...\index.php:19

jlrdw's avatar

@gurds91 just download the code and compare your code to Github code.

1 like
Randy_Johnson's avatar

Show your code. Also why do you use WAMP on local host. If you are using VS CODE just open TERMINAL by pressing CTRL +TILT key and type PHP ARTISAN SERVE.

Then you can view the page at the ip is provides in the terminal.

1 like
gurds91's avatar

@Randy_Johnson I tried this, it says

Could not open input file: artisan

even though I previously had installed composer and laravel in the past..

Please or to participate in this conversation.