mod rewrite failure

Roger arelem at bigpond.com
Tue Mar 11 01:18:25 UTC 2014


Hello all.
I'm going back to learning php and working through 
http://www.youtube.com/watch?v=Aw28-krO7ZM which is how to set up MCV in 
php.
I have Slim installed also with intent to utilise that in the future.

Have a bit of a problem I think with mod_rewrite.
I have run a2enmod rewrite - no errors.
In /etc/apache2/apache2.conf  I have:
  ServerName localhost

<Directory /var/www/>
         Options Indexes FollowSymLinks
         # changed from None to FileInfo March 10
         AllowOverride All
         Require all granted
</Directory>

<Directory /var/www/public>
         Options Indexes FollowSymLinks
         AllowOverride All
         Require all granted
</Directory>
----------========----------
.htaccess:
RewriteEngine On
RewriteCond %{REQUEST_RILENAME} !-d
RewriteCond %{REQUEST_RILENAME} !-f
RewriteCond %{REQUEST_RILENAME} !-l
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
----------========----------

index.php
<?php

// $url = $_GET['url'];

explode('/', $_GET['url']);
print_r($url);

echo 'This is the main ', $url;

require 'controllers/'.$url.'.php';
$controller = new $url;
----------========----------
I have a /controllers directory which contains one index.php file and a 
help.php, both similar. The echo is only a way to see whether it's 
working or not.
<?php

class Index {

     function__construct(){
         echo "We are in Index in the controller"; }
     }
?>
controller
----------========----------
/var/log/apache2/error.log reports:
[Tue Mar 11 11:39:32.215554 2014] [:error] [pid 7257] [client ::1:47416] 
PHP Stack trace:
[Tue Mar 11 11:39:32.215571 2014] [:error] [pid 7257] [client ::1:47416] 
PHP   1. {main}() /var/www/mvc/index.php:0
[Tue Mar 11 11:39:32.215600 2014] [:error] [pid 7257] [client ::1:47416] 
PHP Fatal error:  require(): Failed opening required 'controllers/.php' 
(include_path='.:/usr/share/php:/usr/share/pear') in 
/var/www/mvc/index.php on line 10
[Tue Mar 11 11:39:32.215612 2014] [:error] [pid 7257] [client ::1:47416] 
PHP Stack trace:
[Tue Mar 11 11:39:32.215628 2014] [:error] [pid 7257] [client ::1:47416] 
PHP   1. {main}() /var/www/mvc/index.php:0

My problem is that the main index.php require directive does not find 
the /controllers files.

Without the require command the main index.php works and the $url = 
$_GET['url']; prints the url in the browser but with the require  it 
echoes 'This is the main' and nothing more.

I have the same problem in Slim where requires and includes do not work.

I remember when working with Drupal I could not get the urls to work had 
to use url?=whatever/file
Frankly, I'm lost as to where to look next. Can someone clue me in to 
resolve this.
thank you in advance
Roger




More information about the ubuntu-users mailing list