Remove get method from url

93 Views Asked by At

I want to remove get method from url using htaccess

Bad Url: mysite.com/index.php?sub=usr1
Good Url: mysite.com/urs1

How can I do that?

1

There are 1 best solutions below

6
On

Something like this should work:

<Location /index.php?sub=usr1>
Order Allow,Deny
Deny from all
</Location>

Probably some better solutions though, but I tried to avoid mod_rewrite.

Note that this will allow you to whitelist specific IPs if need be too. This is a basic block, if you're looking to block ALL values for a specific parameter then that will obviously require different code, so please do clarify.

EDIT: After some clarification, I came up with this:

RewriteEngine on
RewriteBase /
RewriteRule ^([^./]+)$ index.php?sub=$1 [L,QSA,NC]

I think this is fine but I'm not sure, will wait for some feedback. My thinking is that it'll grab the value and then replace that to the root URL (example.com/$1 where $1 is your GET parameter value).