Clément S.
Clément S.

Reputation: 411

Strange issue using Mod_rewrite and $_GET variable

After reading tons of SO questions, asking friends and so one, I'm coming here with a strange issue regarding Apache mod_rewrite.

I'm trying to catch http://api.server.com/.../results.php?id=X URL though a RewriteRule.

Quite simple you'll say, I know it, my .htaccess file content is :

Options +FollowSymlinks
RewriteEngine on

RewriteRule ^results/(.*)$ results.php?id=$1

results.php is quite simple for debugging reasons, looks like

    var_dump($_GET);

But this script always return array 0 { }

Shall I specify that I've already tried to clear the flags, and change the (.*) class by others, without effects.

Thanks for your help.

Upvotes: 1

Views: 56

Answers (2)

anubhava
anubhava

Reputation: 785128

You will need to disable MultiViews option here:

Options +FollowSymlinks -MultiViews
RewriteEngine on

RewriteRule ^results/(.*)$ results.php?id=$1 [L,QSA,NC]

Option MultiViews is used by Apache's content negotiation module that runs before mod_rewrite and makes Apache server match extensions of files. So /file can be in URL but it will serve /file.php.

Upvotes: 1

T. Fabre
T. Fabre

Reputation: 1527

Your rewrite rule does not match the URL you are using (http://api.server.com/customer/2/results.php).

The correct URL according to your rule and setup is:

http://api.server.com/customer/2/results/123

However, you mention having placed everything in the /2/ folder. If 2 is the ID you are trying to get, it cannot work -- URL rewriting only works with non-existing paths.

Instead you should place your .htacess and results.php file in the customer folder, and use the following URL:

http://api.server.com/customer/results/2

Or change your rule and URL to:

RewriteRule ^([0-9]+)/results$ results.php?id=$1
http://api.server.com/customer/2/results

Upvotes: 0

Related Questions