title: Rewriting rules in Apache for a different port
body: <p>My Apache(Tomcat)-Spring server runs on port 8080. I want to make a call to localhost default port(80) and want a redirection to take place to port 8080.</p>
  
  <p>I enabled mod-rewrite and the following rule from <a href="https://www.digitalocean.com/community/tutorials/how-to-set-up-mod_rewrite" rel="noreferrer">DigitalOcean</a> works fine.</p>
  
  <pre><code>RewriteRule ^orange.html$ apple.html
  </code></pre>
  
  <p>I read the rewrite rules of apache from <a href="http://httpd.apache.org/docs/2.0/misc/rewriteguide.html" rel="noreferrer">Apache URL Rewriting Doc</a></p>
  
  <p>However the following rules does not work:</p>
  
  <pre><code>RewriteEngine On    # Turn on the rewriting engine
  RewriteCond %{SERVER_PORT} !^80$
  RewriteRule ^/(.*)         http://localhost:8080/$1 [L,R]
  </code></pre>
  
  <p>My intention is to allow cross domain support without enabling CORS in spring controller.(This is a hard rule)</p>
  
  <p>The .htaccess is located in /var/www/html.
  Also I do not want other requests to be redirected on the port 8080 except which are on localhost/(my_specified_string)</p>