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.

marked as duplicate by MadHatter, dawud, mdpc, Andrew B, Ward May 18 '14 at 4:53

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

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.

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.