anhldbk
anhldbk

Reputation: 4587

Configuring .htaccess

I'm writing a PHP web application which is capable of analyzing requested resources before returning them to clients. So I've used .htaccess with the following configuration:

RewriteEngine on
RewriteRule ^(.*)$ query.php?res=$1

And the code for query.php is

<?php
if(isset($_GET['res']))
    echo "Requested resource " . $_GET['res'];
else
    echo "No resource requested"; ?>

The 2 files are placed in the same directory. But the problem is with any URL, the result always be "Requested resource is query.php". Would you please tell me what's wrong? What should I do?

Thanks in advance!

Upvotes: 0

Views: 84

Answers (1)

DaveRandom
DaveRandom

Reputation: 88677

Just add an [L] flag to the rewrite rule and it should fix the problem. My guess is that you may also want a [QSA].

So change the .htaccess to:

RewriteEngine on
RewriteRule ^(.*)$ query.php?res=$1 [L,QSA]

See this page for an explanation of what flags are available and what they do.

Upvotes: 1

Related Questions