0

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?

PHP
  • 49
  • 3

1 Answers1

1

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).

Cillian Collins
  • 728
  • 3
  • 11
  • 1
    _Something like this should work..._ Yes "something" like this should work but not "this".... Have you read OPs question carefully? – B001ᛦ May 16 '18 at 15:25
  • Not sure, does he want a redirect? I assumed he is looking to block the URL posted in OP? – Cillian Collins May 16 '18 at 15:27
  • _does he want a redirect?_ He clearly says: _I want to remove get method from url using htaccess_ and shows an example – B001ᛦ May 16 '18 at 15:28
  • 1
    Yeah, I think I get what you mean. I actually made this before for one of my websites but it was a while back. Tried applying it for the above code, let me know what corrections you can make to what I added to my answer please. – Cillian Collins May 16 '18 at 15:37
  • It doesn't work – PHP May 17 '18 at 05:41
  • Hmm it's working for me. Have you tried going to www.website.com/usr1 ? – Cillian Collins May 17 '18 at 11:08