Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Using htaccess to block port in apache?

Is it possible?

share|improve this question


In order to have Apache process the .htaccess file's directives the port needed to be open, and a client needed to connect to it.

What you might be looking for is using iptables to block the port.

share|improve this answer

You theoretically CAN use rewrite rules in .htaccess using the %{SERVER_PORT} variable to do something different with requests coming in on a specific port, which could also mean denying access to resources.

However, this is almost certainly not the best way to get to what you're trying to accomplish.

share|improve this answer

please use RewriteCond %{SERVER_PORT} !3306$

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.