arcologies
arcologies

Reputation: 752

mod_rewrite in .htaccess not working get

I have a .htaccess file in a directory that is supposed to redirect all requests to query.php, adding the requested file as a GET var:

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

Should work fine right? Except when I try going to anyfile.php, query.php print_r's the $_GET like so:

Array ( [page] => query.php )

I feel like this maybe has something to do with Apache rewriting the already re-written url or something.

In short, I am being redirected correctly, but somehow the GET var is being messed up.

Can anyone give me a hand? I've been working at this for ages and I just can't figure it out!

Upvotes: 0

Views: 89

Answers (2)

sanmai
sanmai

Reputation: 30941

Don't reinvent a wheel, look what others use for that purpose:

Options -MultiViews
RewriteEngine On
# This line checks whether file exists:
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^ index.php [L]

You'll find a page URI in $_SERVER['REQUEST_URI']. Swap index.php for query.php and you're done.

Upvotes: 1

dambrisco
dambrisco

Reputation: 865

I'm surprised you're not getting a "Too many redirects" error, honestly.

Adding a RewriteCond similar to the following should take care of the issue.

RewriteCond %{REQUEST_URI} !^query\.php

Upvotes: 0

Related Questions