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.

robsch
  • 137
  • 7
Rook
  • 2,615
  • 5
  • 26
  • 34

2 Answers2

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.

James Polley
  • 2,089
  • 15
  • 13
1
RewriteCond %{QUERY_STRING} .+
RewriteRule ^(.*)$ /$1? [R=301,L]
Rook
  • 2,615
  • 5
  • 26
  • 34