简体   繁体   中英

PHP Front Controller and .htaccess with XAMPP and Windows

I'm trying to get a simple front controller for routing set up. This is the front-controller.php file I have:

<?php

if ($_SERVER['REQUEST_URI'] == '/help') {
    include 'help.php';
}

this is a .htaccess file I have in the folder with my index.php (which is under htdocs/wad)

RewriteEngine On
RewriteRule . /front-controller.php [L]

In httpd.conf I changed all instances of the AllowOverride None line to AllowOverride All and I uncommented the LoadModule rewrite_module modules/mod_rewrite.so line.

I am getting Error 404 if I try to go to localhost/wad/help and even localhost/wad: http://puu.sh/cE6WT/2e4c645555.png

The help.php file exists. I want to be able to browse to localhost/wad/help and have it load (in the same page, not redirect to it). Am I going about this the wrong way?

Thanks

I think, there is a much more better way, if you are use your .htaccess like this:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /front-controller.php?action=$1 [QSA,L]

And then in your front-controller.php you can use the $_GET["action"] parse it, and route where you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM