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

< GDB >'s avatar

.htaccess setup - PHP practitioner course - Make a router (ep16)

Hi all,

I'm following the PHP Practitioner course, but experience difficulties to set up my router according to ep. 16.

I tried to configure the .htaccess file in multiple different ways, to no avail. Keep getting the error:

"Fatal error: Uncaught Exception: No route defined for this URI in /Applications/MAMP/htdocs/laracast/PDO/c_routing/core/router.php:30 Stack trace: #0 "

I though it might have something to do with my path for the project in (mamp) htdocs (/laracast/PDO/c_routing/), but can't figure out what I'm doing wrong.

This is one of my attempts (probably focussing to much on the path...). Anyone that can help me understand what I'm doing wrong?

Thank you in advance!!

.htaccess file :

RewriteEngine On

RewriteBase /laracast/PDO/c_routing/

RewriteRule ^index.php$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . /laracast/PDO/c_routing/index.php [L]

more info (folder structure / scripts ) : https://imgur.com/a/KzL0odh

// UPDATE //

$uri = string(22) "laracast/PDO/c_routing

routes array = array(4) { [""]=> string(21) "controllers/index.php" ["about"]=> string(21) "controllers/about.php" ["about/culture"]=> string(29) "controllers/about-culture.php" ["contact"]=> string(23) "controllers/contact.php" }

Based on the dump above, a friendly redditor advised me to remove the prefix from $uri. Which resulted in no more error but just a blank screen (instead of the index) :-D (laughing but actually crying a little) I think I just postponed the issue no? Or would it have another reason for blank screen

0 likes
8 replies
Snapey's avatar

definitely your hosting should be configured to serve the folder containing index.php and your .htaccess as what is known as the document root

Google setting document root in MAMP

1 like
< GDB >'s avatar

Thanks for the reply @Snapey.

Could you inform me why i would need to reconfigure the hosting?

Currently it is the default SSD/applications/mamp/htdocs

if I change this however, my .htaccess files for other projects will not work anymore... Or am I completely off here?

laracoft's avatar

@gillesdeb .htaccess is a apache topic. Give us an idea of your folder structure.

  1. Which folder is Laravel installed?
  2. What URL loads the contents of SSD/applications/mamp/htdocs?
1 like
< GDB >'s avatar

Hey @laracoft ,

Thnx for your input!

Currently I do not have Laravel installed, I'm following the PHP Practitioner course here on Laracasts. In EP. 16 (https://laracasts.com/series/php-for-beginners/episodes/16), Jeffrey explains the routing process. However he skips the part where you need to setup the server to route everything to the index.php

Hence the .htaccess file. In the comments there are numerous explanations / solutions (?) from various people. Unfortunately none of these seem to work.

The issue is that when i type for example : example.com/about/culture it does not look for the index.php..

I'm quite sure mamp is configured correctly as I have made use of .htaccess files for another tutorial.

I can't seem to upload pictures here, but https://imgur.com/a/KzL0odh this might give a better overview

laracoft's avatar

One Apache web server can support many domains, and each domain will have it's own folder with 1 .htaccess inside

  1. What is the timing where Jeffery is explaining?
  2. How many domains have you configured on your server?
  3. And do you know the root folder for each domain?
1 like
< GDB >'s avatar

@laracoft

  • 1 Jeffrey did not explain this part... Conveniently left it out ;-) > But it is a issue as the comment section is quite full of these remarks...

So for question 2 and 3, I'll try to answer to my best knowledge, might as well make a complete fool out of myself.. here i go...

I'm using mamp, store every project in the folder : SSD/applications/mamp/htdocs

  • 2 exactly 10 different projects

http://localhost:8888

  • 3 As far as i understand, every project is stored in SSD/applications/mamp/htdocs

    so in this case : ssd/applications/mamp/htdocs/laracast/PDO/c_routing/

Only difference I have now in comparison with another project (where .htaccess works) is that this folder 'ssd/applications/mamp/htdocs/laracast' contains different chapters of the course. but each folder is a duplicate of previous course.

Does this make sense ?

laracoft's avatar

@gillesdeb

  1. 10 projects doesn't mean 10 domains. If you only use localhost:8888, then you have only 1 domain.
  2. Assuming you have only 1 domain, i.e. localhost, then you only have 1 .htaccess, all your 10 projects will be affected by the changes you make to it.

I'm keeping things simple here because you actually configure Apache to support .htaccess in each subfolder.

Hope the above helps.

I will update again once I find some time to watch ep16.

1 like
< GDB >'s avatar

@laracoft

thnx for explaining that,

  1. wasn't really sure how to define it as the localhost:8888 url changes for each project. But that is clear now (learned something new).

  2. Based on this, i removed all other projects (the one with previous .htaccess included), with the hope/assumption that this would resolve the issue. Unfortunately, it did not... :-)

Thank you again for the suggestions / help and possible follow up!!!

Please or to participate in this conversation.