1

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

Vlad Vidac
  • 978
  • 1
  • 10
  • 26
  • 1
    I am open a filezilla, create a .htacess on the remote server, and download to my localhost. But there are several ways to create a .htaccess on windows. http://stackoverflow.com/questions/5004633/how-to-manually-create-a-file-with-a-dot-prefix-in-windows-for-example-htacce – vaso123 Nov 05 '14 at 10:41
  • Thank you! Now the .htaccess file is definitely being used but I can no longer access any page, I get Object not found even on localhost/wad/ – Vlad Vidac Nov 05 '14 at 10:51
  • edit your question, and show us your whole .htaccess file content. – vaso123 Nov 05 '14 at 10:53
  • edited - that is the whole file content – Vlad Vidac Nov 05 '14 at 10:57

1 Answers1

3

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.

vaso123
  • 12,347
  • 4
  • 34
  • 64