Hello, My domain is accessible via 2 ways: http://www.domain.com/ http://www.domain.com/index.php The index.php itself has GET form, so sometimes the URL will be like: http://www.domain.com/?var=12345 http://www.domain.com/index.php?var=12345 What I want to do with htaccess is to block the URL http://www.domain.com/?var=12345 entirely. If someone tries to access this URL, they will encounter an error response code. No redirection. The blockage should only work for that URL, so if the URL is http://www.domain.com/?var=999 then it should work fine. I've been trying to search on Google, but I'm out of keywords to find exactly what I want. Thank you in advance.
Something like this maybe: if (stripos($_SERVER['REQUEST_URI'],"var=12345") !== false) // looks for var=12345 { // do nothing } else { header("Location: http://urlToSomeWhere.com"); // send the visitor somewhere exit; } PHP:
MyVodaFone was suggesting that you add that code to your index.php file, and I think he's right, but his example code isn't really what you asked for. I think what you want is something more like: if (stripos($_SERVER['REQUEST_URI'],"var=12345") !== false) { header("Location: /error_message_page.html", TRUE, 403); exit; } Code (markup): which sends the HTTP error code "403 - Forbidden" and displays the page in the "Location:" area. Be sure to leave that as a relative URL. Don't add the "http://" there. And remember that this code must be inserted before the page outputs anything else. Good luck!
I'm unable to edit index.php as the file was encrypted. Moreover, if I edit index.php it would affect both http://www.domain.com/?var=12345 and http://www.domain.com/index.php?var=12345 -- I only want it to affect the /?var one only. That's why I think htaccess is most suitable for this. Is it even possible to do this with htaccess?
I doesn't matter if its encrypted you can still add your own code on the very first line and the script looks for var=12345 in the url the two urls above are the same, index.php is loading regardless <?php code ?> the rest of your script is below