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.
I enabled mod-rewrite and the following rule from DigitalOcean works fine.
RewriteRule ^orange.html$ apple.html
I read the rewrite rules of apache from Apache URL Rewriting Doc
However the following rules does not work:
RewriteEngine On # Turn on the rewriting engine
RewriteCond %{SERVER_PORT} !^80$
RewriteRule ^/(.*) http://localhost:8080/$1 [L,R]
My intention is to allow cross domain support without enabling CORS in spring controller.(This is a hard rule)
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)
ProxyPass is what was needed here and not rewrite engine.
Following config lines in the 000-default.conf
present in /etc/apache2/sites-available
did the trick.
ProxyPass /servlet-name http://localhost:8080/servlet-name
ProxyPassReverse /servlet-name http://localhost:8080/servlet-name
This redicrected any request on /servlet-name
to http://localhost:8080/servlet-name
.
One can replace "servlet-name" above with their respective servlet name.
More info here: http://httpd.apache.org/docs/2.2/mod/mod_proxy.html
You can use this rule in root .htaccess:
RewriteEngine On
RewriteCond %{SERVER_PORT} =80
RewriteRule ^my_specified_string http://localhost:8080%{REQUEST_URI} [NC,L,R]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With