1

I have URLs like /?test that I want to rewrite to /page.php?page=test

I tried like this but for some reason it doesn't work.

RewriteRule ^\?([a-z0-9\-\+]{3,20})/?$ /page.php?page=$1 [NC,QSA]

What am I doing wrong?

mote
  • 1,429
  • 13
  • 23
Martin
  • 5,197
  • 11
  • 45
  • 60

1 Answers1

5

The query string can only be tested with the RewriteCond directive. The RewriteRule pattern is only tested against the URL path (in .htaccess files the URL path without the per-directory prefix).

So try this:

RewriteCond %{QUERY_STRING} ^[a-z0-9-+]{3,20}$ [NC]
RewriteRule ^$ /page.php?page=%0 [QSA]
Gumbo
  • 643,351
  • 109
  • 780
  • 844
  • Ah I see. It almost worked but the querystring page is empty when i'm trying to get it in page.php – Martin Aug 26 '09 at 20:19