views:

111

answers:

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 for all files on the system.

Thank you.

+1  A: 

The following rule should take care of it (for all URLs on your site, as mentioned):

RewriteCond %{QUERY_STRING} .+
RewriteRule ^(.*)$ /$1? [R=301,L]

I must admit I'm a bit curious as to why you would want to do this... I don't think it has much SEO value, and you could just ignore the $_GET variables inside your scripts?

zombat
Well done! We decided to enforce this coding convention becuase a client didn't want people to know that they where running php and this is a dead giveaway:http://localhost/?=PHPE9568F34-D428-11d2-A769-00AA001ACF42 .
Rook
I don't think rewriting your URLs to remove query strings is the best way to hide the fact that you're using PHP (it also ruins your ability to use HTTP GET requests with query parameters). Generally you'd want to get rid of the ".php" endings on your scripts and URLs. As well, that link you left in your comment looks like a session identifier to me... removing that is likely to break your session handling!
zombat