So I know this question has been asked 20 other times and 20 different ways but after all of my researching I still can't seem to figure this out. My setup works great until I type in a URL with a trailing slash and then I get 404 errors. For example, when I type in the URL mydomain.com/first
and hit enter, it works fine. When I type in mydomain.com/first/
and hit enter, it works fine then too. But then, if I type in mydomain.com/second
it sends me to mydomain.com/first/second
and throws a 404 error.
Here is my entire htaccess page:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9_\-]+)/?$ index.php?url=$1 [NC,L]
</IfModule>
My index page:
<?php
define('ROOT_DIR', dirname(__FILE__) . '/'); // Define the root directory for use in includes
require_once (ROOT_DIR . 'library/bootstrap.php');
$url = strtolower($_GET['url']);
include(ROOT_DIR . 'views/headerView.php');
switch($url)
{
case "first": include(ROOT_DIR . 'views/firstPageView.php');
break;
case "second": include(ROOT_DIR . 'views/secondPageView.php');
break;
default: include(ROOT_DIR . 'views/homeView.php');
}
include 'views/footerView.php';
?>
And the default homeView template:
<p>This is the home page.</p>
<p>To the first page. <a href="first">First Page</a></p>
<p>To the second page. <a href="second">Second Page</a></p>
I would think that since the slash is optional and not part of the back reference, that the slash would be left off the URL after the page load but in my above example, its clearly not. Any advice would be most appreciated. Thank you