homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

Using Apache to direct to a specified port

 3:13 pm on Apr 20, 2014 (gmt 0)


I'm a newbie at Apache.

I'd like to use it to enable a user to type a "URL" that is directed to "URL:specified port number"

I've found the following on the Internet:


Create: /Library/WebServer/Documents/.htaccess

RewriteEngine on
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ http://example.com:8080/$1 [R,L]

Edit: /etc/apache2/httpd.conf

In <Directory "/Library/WebServer/Documents">
Change to : AllowOverride All
(allow .htaccess files)


I'd appreciate a fuller explanation of this. I'm using OS X.

Will it work ?

What about write permissions to these files ? How do I change them so that I do not mess things up ?



[edited by: Ocean10000 at 5:44 pm (utc) on Apr 20, 2014]
[edit reason] Examplified [/edit]



 5:57 pm on Apr 20, 2014 (gmt 0)

Are we talking about a production server or something local (as implied by "80")? Where are the users? Is this an internal network?

At an absolute minimum, you have to Listen on the appropriate port number, or the request will never reach the server. This line has to go in the config file, not in htaccess.

OS X point what?


 9:34 pm on Apr 20, 2014 (gmt 0)


It's on the Internet, currently at:


I'd like it to be: [URL...]

I'm using Mavericks 10.9.2



 11:31 pm on Apr 20, 2014 (gmt 0)

But, but, splutter-- that's the exact opposite of the original question :(

Redirecting from a with-port-number URL to a without-port-number one is trivial. If you've got a domain-name-canonicalization redirect in place, you're already doing it.

Redirecting to a specified port by name is trickier. Do you want the port number to be an explicit part of the URL? That's a separate issue from simply using a particular port.


 12:17 am on Apr 21, 2014 (gmt 0)

I apologize for any confusion I engendered.

I provide a service (WADO; Web Access to Dicom Objects) that uses a certain port: 3333, in my case

I would like the User to be able to simply type in the URL without specifying the port number in the URL that is, by having to remember to type ":3333" after the URL

So, "Redirecting from a with-port-number URL to a without-port-number " in your formulation.




 7:46 am on Apr 21, 2014 (gmt 0)

Are you starting to figure out that I'm just stringing you along until someone shows up who speaks Apache? ;) (phranque? Where are you, anyway?)

Do you want to require a no-port URL, or simply to allow it as an alternative? Right now, what happens if users type in the URL without the port number? Is there any potential conflict? (That is, otherwise-identical URLs providing different connections depending on port number specified.) Do they reach the intended site? If requests without explicit port number don't reach the site or service, that's a whole different question.

What I'm trying to figure out is how this differs from the ordinary canonicalization redirect that you've almost certainly got in place already. The one that goes

RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

except that something tells me you're not dealing with http/1.0 requests here, so the ()? element can be omitted.

:: detour to IANA ::

Uhm... this is http we're talking about, right? People typing things into their browser, and then stuff happens that they don't need to know about?


 12:39 pm on Apr 23, 2014 (gmt 0)

welcome to WebmasterWorld, Howard!

is port 3333 configured as the default port your web service's hostname?
are you serving web urls from any other ports on that hostname?


 2:45 pm on Apr 23, 2014 (gmt 0)


1. Go to : radchest.macminicolo.net

2. Go to: radchest.macminicolo.net:3333

I may want a user to type 1. to automatically achieve 2.




 7:03 pm on Apr 23, 2014 (gmt 0)

Hence the confusion. This ought to happen by default, unless there's something wonky about port 3333. Does the server currently listen on 3333? What about other port numbers?

:: detour to check something ::

Listen is now a required directive. If it is not in the config file, the server will fail to start. This is a change from previous versions of Apache.

OK, that answers that. What do(es) your Listen line(s) currently say? In addition to number, does it specify http?

What do you want the browser's address bar to say?

Edit: phranque, if he's using the same URL on more than one port, does he also need to say something in the Virtual Hosts area?


 12:57 am on Apr 24, 2014 (gmt 0)

howardm, please answer the questions I asked.

lucy24, yes.


 3:39 am on Apr 24, 2014 (gmt 0)

I'll try.

When you go the address I provided, you'll see that it is an application called OsiriX. It provides cases via a Web Portal.

The Web Portal is associated with port 3333.

If you go to the bottom of this Web Page, you'll see that I now have a link to it:

The Web Page is radchest.macminicolo.net.

The link to enter the actual Portal is: radchest.macminicolo.net:3333

Since this thread started, I configured it this way, and I think it'll work for me.

So, thanks for your help.



 4:29 am on Apr 24, 2014 (gmt 0)

howardm, please use example.com in Apache Web Server posts.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved