I've the next file structure:


and also the following rules during my .htaccess file:

<IfModule mod_rewrite.c>

  RewriteEngine on
  RewriteRule ^(.*)$ index.php?q=$1 [L]


After I navigate to http://localhost/framework/example I'd expect the query string to equal 'framework/example' but rather it equals 'index.php'. Why? And just how will i obtain the variable to equal when I am planning on?

Because you have rewritten the url with RewriteRule and also have already put the prior road to the q. So only use $_GET['q']

Your rewrite rules are looping. Mod_rewrite will not stop spinning before the URI (with no query string) is identical pre and post it is going with the rules. Whenever you initially request http://localhost/framework/example this is exactly what happens:

  1. Rewrite engine takes /framework/example and strips the key "/"
  2. framework/example is defined with the rules
  3. framework/example will get rewritten to index.php?q=framework/example
  4. Rerite engine blogs about the pre and post, framework/example != index.php
  5. index.php?q=framework/example dates back with the rewrite rules
  6. index.php will get rewritten to index.php?q=index.php
  7. Rewrite engine blogs about the pre and post, index.php == index.php
  8. Rewrite engine stops, the resulting URI is index.php?q=index.php

You have to give a condition to ensure that it will not rewrite exactly the same URI two times:

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/index\.php
RewriteRule ^(.*)$ index.php?q=$1 [L]