Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

Thank you.

share|improve this question

marked as duplicate by MadHatter, dawud, mdpc, Andrew B, Ward May 18 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.

2 Answers 2

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.

share|improve this answer
    
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
up vote 1 down vote accepted
RewriteCond %{QUERY_STRING} .+
RewriteRule ^(.*)$ /$1? [R=301,L]
share|improve this answer

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