Yes, you can trim the port from the host header. Just compare with %{HTTP_HOST}
and use %1
backlink. For instance:
RewriteCond %{HTTP_HOST} ^([^:]+)(:[0-9]+)?$ RewriteRule ^ http://%1:12345/ [R,L]
Just keep in mind that relaying %1
can only be used in the first parameter of the RewriteCond
, and not in a match:
RewriteCond %{HTTP_HOST} ^([^:]+)(:[0-9]+)?$ RewriteCond %1 ^the.hostname.com$ [NC]
ok
RewriteCond %{HTTP_HOST} ^([^:]+)(:[0-9]+)?$ RewriteCond %{REQUEST_URI} ^%1
NOT OK
source share