Page 377 - PHP Novice to Ninja 6th Edition - blank 'route' not being returned

I have done the following as described as follows:
In index.php, we replace else if ($route === ‘joke/home’) { with else if
($route === ‘’) {. If we refresh the home page, it should display as expected.

However when I click on my HOME link( <a href=“/”>Home</a>), the following is the URL is returned:
http://localhost/index.php?route=index.php

This is in my htaccess:
RewriteRule ^.*$ /index.php [NC,L,QSA]

Am new to REGEX and took this from Pg375. This I believe loads index.php if the requested location is not found.

How then does one create a HOME link of ‘/’ while still having the REGEX in place to default a not found address to /index.php?

Thank you in advance.
Jeremy

Hi Jeremy,

What do you mean by “The URL is returned”? If you are seeing that in the address bar it means that index.php is triggering the rewriterule, make sure you have the two RewriteCond directives in your .htaccess file.

Hi Tom,

Thanks for the reply, yes, that is what I mean. Ok, here is my .htaccess file:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^.*$ /index.php [NC,L,QSA]

So this is saying that any blank must be replaced with /index.php ? But I need a blank for my index.php check for the Homepage.

Not sure how to get my code in the index.php to direct to the home page, this is what I have:

        else if ($route === '') {
            include __DIR__ .'/classes/controllers/JokeController.php';
            $controller = new JokeController($jokesTable,$authorsTable);
            $page = $controller->home();

Thank you.

I’m not sure where the URL http://localhost/index.php?route=index.php is coming from, there is nothing in the RewriteRule that adds the route URL variable. If you have set up a redirect previously it may be a cache issue, can you try visiting just http://localhost/ in a different browser?

Hectic, thank you Tom, must have been a cache issue, opened up in IE and worked perfectly.

Thanks for your help.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.