1

How can I use mod_rewrite to remove everything after the ? (question mark) in a URL?

For instance:

http://127.0.0.1/ALL_FILES.php?test=1

after mod_rewrite:

http://127.0.0.1/ALL_FILES.php

For php this means that the $_GET super global will always be empty.

0

2 Answers 2

5

Quoting from the mod_rewrite docs:

The Pattern will not be matched against the query string. Instead, you must use a RewriteCond with the %{QUERY_STRING} variable

Something along the lines of:

 RewriteCond %{QUERY_STRING} .
 RewriteRule ^/index.php /index.php? [L,R]

should do what you need. If you don't care about what is displayed to the user, but only what gets passed down to php, you can leave out the R flag.

2
  • I want the rules to work for all files on the system, not just index.php
    – Rook
    Jan 5, 2010 at 20:03
  • 3
    Change the rewrite line to this: RewriteRule ^(.*)$ $1 [L,R] Jan 5, 2010 at 21:14
1
RewriteCond %{QUERY_STRING} .+
RewriteRule ^(.*)$ /$1? [R=301,L]

Not the answer you're looking for? Browse other questions tagged .