@StephenOstermiller's answer has done a great job of describing the .htaccess
file / front-controller process, but I thought I'd address the other issue you raised...
If I comment out the things in the ".htaccess" file, nothing changes
That's because the format of the URLs you are using (eg. /ROUTER/index.php/home
) completely negates the need for the .htaccess
file to begin with. You are calling index.php
(the "front-controller") directly in the URL itself and passing /home
as additional pathname information (aka. path-info).
The .htaccess
file is still processed, but the 2nd condition (RewriteCond
directive), which checks that the request does not map to a physical file, fails (index.php
is a physical file) so the rule is not triggered (it does nothing).
The additional path-info on the URL is available to PHP in the $_SERVER['PATH_INFO']
superglobal. So, if you are using URLs of the form /ROUTER/index.php/home
then you could write your front-controller (index.php
) like this instead (simplified):
// URLs of the form "/ROUTER/index.php/home"
$request = $_SERVER['PATH_INFO'];
switch ($request) {
case '':
case '/home':
:
case '/about' :
:
}
(As noted above, this is not making use of .htaccess
)
On the other hand, your .htaccess
file allows you to have URLs of the form /ROUTER/home
(or simply /home
), avoiding you having to include index.php
in the URL, which is then internally rewritten to index.php
(by the rule in .htaccess
). You then use $_SERVER['REQUEST_URI']
(as in your original script) to access the requested URL in PHP.
For example (simplified):
// URLs of the form "/ROUTER/home"
$request = $_SERVER['REQUEST_URI'];
switch ($request) {
case '/ROUTER/':
case '/ROUTER/home':
:
case '/ROUTER/about' :
:
}
However, your existing .htaccess
file is not configured correctly for this. The .htaccess
file is assuming index.php
is located in the document root, but your URLs suggest you have a /ROUTER
subdirectory, in which index.php
(the "front-controller") is located.
If your .htaccess
file is in the /ROUTER
subdirectory at /ROUTER/.htaccess
then remove the RewriteBase
directive entirely.
If, however, your .htaccess
file is located in the document root then you will need to change your RewriteBase
directive to read:
RewriteBase /ROUTER
(Setting RewriteBase /ROUTER
in both cases will also work.)