Score:1

htaccess, block access a url with parameters

ki flag

If I want to block access to example.com/path/?xxxx (xxxx is variable), but allow access to example.com/path/, how should I write it in my .htaccess?

Rohit Gupta avatar
be flag
Are these urls valid ? Are there files there ?
Sanata avatar
ki flag
Ex: domain.com/someone/someone.php real and valid url. Attackers use domain.com/someone/someone.php?ddfdfd to bring down my site. If I write that parameter after a valid url, it does not cause a 404 error, it loads the url domain.com/someone/someone.php
Score:0
kz flag

You can block access (eg. trigger a 404 Not Found) when a specific path (/path/) is requested with any query string using mod_rewrite at the top of the root .htaccess file.

For example:

RewriteEngine On

RewriteCond %{QUERY_STRING} .
RewriteRule ^path/$ - [R=404]

The above matches the URL /path/ exactly. (Note there is no slash prefix on the URL-path matched by the RewriteRule pattern - the first argument.)

To block all URLs that contain any query string then change the RewriteRule pattern to just ^ (simply a start of string assertion, so it's successful for any URL-path). For example:

:
RewriteRule ^ - [R=404]
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.