Page 1 of 1

mod_rewrite passes filename without $_GET values

Posted: Mon Mar 21, 2011 6:45 pm
by Weiry
htaccess file

Code: Select all

RewriteEngine On
RewriteRule ^([^/]*)$ dl.php?f=$1 [L]
php file

Code: Select all

<?php
require_once './fileManager.php';

$fm = new FileManager();
if(isset($_GET['f'])){
        $fm->getFile($_GET['f']);
}
?>
Input URL:
http://my.domain.com/096848478a2d6f

Here's the curious bit:
My understanding of mod_rewrite is that the ACTUAL file requested by Apache is "dl.php?f=$1".
Which in this case should be "dl.php?f=096848478a2d6f"

This 'should' state to apache to get the file 'dl.php' with a $_GET of 'f=096848478a2d6f'

So in theory, the $_GET array SHOULD look like the following:
Array ( [f] => 096848478a2d6f )

However when i print_r($_GET) in the dl file.. it returns
Array ( [f] => dl.php )

Any suggestions towards a solution?

Re: mod_rewrite passes filename without $_GET values

Posted: Mon Mar 21, 2011 7:36 pm
by Weiry
Ok ive had a bit of a play around with various htaccess rules...

Final Rule which seems to be working correctly.

Code: Select all

RewriteEngine On
RewriteRule ^([^/\.]+)$ dl.php?f=$1 [L]