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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.