Johan Larsson
Johan Larsson

Reputation: 175

Redirect based on port number?

Is it possible to redirect domain.com:88 to domain.com:8080 using htaccess & mod_rewrite? And example please?

If htaccess can't do it, waht are other options?

Upvotes: 0

Views: 2025

Answers (1)

arkascha
arkascha

Reputation: 42875

If you get requests on different ports you need to have servers listening on those ports. Inside those servers you can certainly configure rewriting rules, you don't even have to check the port, since it is implicitly given inside the servers logic.

Note that you can configure several virtual servers inside an apache http server.

You can also configure a single server to listen on several ports. Check for documentation about the Listen configuration option inside the http server configuration. Then indeed you have to test for the port. You can do that inside the rewriting module by using the RewriteCond command together with the SERVER_PORT variable. So something like:

RewriteEngine on
RewriteCond ${SERVER_PORT} 88
RewriteRule ^(.*)$ http://some.server.addr:8080/$1 [QSA,L]

Upvotes: 1

Related Questions