mod_rewrite passes filename without $_GET values

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Weiry
Forum Contributor
Posts: 323
Joined: Wed Sep 09, 2009 5:55 am
Location: Australia

mod_rewrite passes filename without $_GET values

Post 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?
User avatar
Weiry
Forum Contributor
Posts: 323
Joined: Wed Sep 09, 2009 5:55 am
Location: Australia

Re: mod_rewrite passes filename without $_GET values

Post 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]
Post Reply