Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache: Rewrite URL in the Background

This question is probably too simple but I cannot get it to work despite hours of testing (and even crashing the server twice o.o ).

The issue is asked frequently: A Tomcat server is accessible through: "domain.net:8080/theserver/" and I want it to be accessible directly on "domain.net/". Just that should also be visible in the user's browser.

The engine "Plesk" which I'm using to configure the site offers a command field for such things. Using the following lines, I've established visible redirecting:

ProxyRequests off
RequestHeader      unset  Accept-Encoding
RewriteEngine     on
RewriteRule ^(/.*)      http://www.domain.net:8080/theserver [P]

The redirection doesn't happen in the background though. When I type domain.net into the browser, it switches to "domain.net:8080/theserver/".

What's the right way to make this happen in the background? "theserver" is the root-location which should be accessible on the server for now.

Huge thanks in advance!

like image 683
DragonGamer Avatar asked Feb 09 '23 10:02

DragonGamer


1 Answers

  1. Make sure Rewrite Module of webserver is enabled.
  2. Make sure apache listens on port 80 and 8080 both.
  3. Add this to .htaccess file in the root BUT NOT in the subdirectory "theserver".

    RewriteEngine on

    RewriteCond %{HTTP_HOST} ^(www.)?domain.net$

    RewriteCond %{REQUEST_URI} !^/theserver/

    RewriteCond %{REQUEST_FILENAME} !-f

    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteRule ^(.*)$ http://domain.net:8080/theserver/$1

    RewriteCond %{HTTP_HOST} ^(www.)?domain.net$

    RewriteRule ^(/)?$ http://domain.net:8080/theserver/index.php [L]

like image 81
Alpesh Panchal Avatar answered Feb 12 '23 18:02

Alpesh Panchal