Jump to content

htaccess through port number


Zane

Recommended Posts

another question

 

Is it possible to popup an htaccess logon box for when someone tries to access a certain port number

 

So if someone tries to access stuff on port 8080

how do I restrict and authorize it

 

 

and I guess my next problem would be

how do I distinguish in Apache which port a folder is part of

if I have all my folders in htdocs (the web root) and I want say my images folder on port 8080

would I have to take it out the web root and put it in a folder in the apache root somewhere....what

how you see what I'm getting at?

Link to comment
https://forums.phpfreaks.com/topic/2824-htaccess-through-port-number/
Share on other sites

Is it possible to popup an htaccess logon box for when someone tries to access a certain port number

If you use a VirtualHost you can add the directives for basic authentication

<VirtualHost host:8080>
   AuthType Basic
   AuthName images
   AuthUserFile /path/to/pass_file
   require valid-user
</Virtualhost>

how do I distinguish in Apache which port a folder is part of

if I have all my folders in htdocs (the web root) and I want say my images folder on port 8080

In a .htaccess file in your root you could have the following

RewriteCond %{SERVER_PORT} !=8080
RewriteRule ^images/ - [F]

You should be able to use the following inside the VirtualHost directive to have the same VHost settings applied for access on the different ports. However, the %{SERVER_PORT} variable seems to be incorrectly filled with the port listed first in the directive.

<VirtualHost host:80 host:8080>
</VirtualHost>

I had to put multiple VHost directives for the port listed in %{SERVER_PORT}to be accurate. I haven't checked what happens in Apache 2.0, and I'm not using the most recent versions of either.

 

It may ultimately be better to put a section in the Vhost for port 80 to deny access to the directory instead of using the .htaccess file.

 

EDIT: Apache 2.0 apparently has the correct SERVER_PORT value when you use the Multiple listings of host:port in the Virtualhost.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.