RewriteRule for Wildfly 14 behind a proxy -> 404 - .htaccess

I have a Vaadin 10 App running on wildfly 14 behind a proxy (from my hoster), but I can't reach the root path where my app is deployed (404). If I deploy on a specific path, like "/example", I reach my app.
I guess it's the RewriteRule. Here is my actual rule:
RewriteEngine on
RewriteRule ^(.*) http://localhost:8080/$1 [P]
There is more confusion: If I make a request mydomain.com/example/ all goes fine. The request mydomain.com/example leads to localhost:8080/example/.
If I change the rule to:
RewriteRule ^(.*) http://localhost:8080/example/$1 [P]
it is the same like a deployment on the root path.
With a non vaadin app, like https://github.com/kumar-shantanu/wildfly-demo-war, and I change to it's path in the RewriteRule, all works fine.
I tried a lot, and to be honest, I don't know much about configuring the RewriteRule.
What could it be?

ProxyPass do the job:
ProxyPass http://localhost:8080/
ProxyPassReverse http://localhost:8080/

Related

How to serve Express/node API to subdomain?

I have a tiny Express app serving on port 35000 on my web server, and it's accessible from mywebsite.com/api using the following .htaccess code (works perfectly, just sends "hello world" to the browser).
RewriteEngine On
RewriteRule ^api/(.*) http://127.0.0.1:35000/$1 [P]
I have set up a subdomain at api.mywebsite.com linked to a separate directory on my server and if I put web files here I can see them at the URL, so that's working fine. I'd like to move my API to api.mywebsite.com so I've created the following .htaccess file in the directory for the subdomain.
RewriteEngine On
RewriteRule ^(.*) http://127.0.0.1:35000/$1 [P]
But navigating to api.mywebsite.com returns a "Not found" error from Express, with a log of 404 index.php. Why is an index.php file expected? I'm happy to at least get the error because that means Express is communicating through the subdomain, but it's not giving me my "hello world" message.
I've had a look at Express vhost from other question but am struggling to understand if that's applicable here or if I'm missing a simple .htaccess rule. Any help would be great thank you.
Just to follow up, this solved my question: htaccess proxy to node app
My .htaccess file in my subdomain directory is now:
DirectoryIndex disabled
RewriteEngine On
RewriteRule ^(.*)$ http://127.0.0.1:35000/$1 [P,L]
RewriteRule ^$ http://127.0.0.1:35000/ [P,L]

Apache redirect of a node app to a folder with .htaccess

I have a shared hosting. The domain mydomain.com points to /home/myuser/www, and I have my app in /home/myuser/www/myapp. I want to access to my node app via mydomain.com, and I think have to redirect via .htaccess file. All my assets are built to /dist folder in the app, with server.js in /dist/server.js.
I have this configuration, but it fails:
RewriteEngine On
RewriteRule ^/myapp$ http://127.0.0.1:4000/ [P,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/myapp/(.*)$ http://127.0.0.1:4000/$1 [P,L]
In local my app is happily running in http://localhost:4000; how should I configure the /home/myuser/www/.htaccess file?
You can use the mod_proxy for the same. (It is enabled by default in apache, but make sure it is).
The rule will be
ProxyPass / http://127.0.0.1:4000/
ProxyPassReverse / http://127.0.0.1:4000/
The above rule is passing all the root request to internal port of your Node JS app with out user knowing about it (different from a rewrite)
Do restart the apache server for the effects to be seen.
You can also refer the blog post for the same

htaccess proxy to node app

I am trying to proxy subdomain to node application which is running on port 3000. It proxies requests to files e.g subdomain.domain.com/jquery.js. It works fine and shows file served by node. But when I try to access the root of subdomain then I guess apache tries to find index.php and fails with message Cannot GET /index.php. How can I make it work so it will serve whatever provided by node app?
my htaccess
RewriteEngine On
RewriteRule ^(.*)$ http://127.0.0.1:3000/$1 [P,L]
RewriteRule ^$ http://127.0.0.1:3000/ [P,L]
RewriteEngine On
DirectoryIndex disabled
worked out

Apache redirect query

I'm stuck at the below scenario.
I've an application deployed in tomcat named "foo". I'm using mod_proxy at apache level to redirect the request from apache to tomcat. Below is the config for it.
ProxyPass /foo https://dev.apprlc.com:8080/foo
ProxyPassReverse /foo https://dev.apprlc.com:8080/foo
I want to show maintenance page to the users when I'm doing some maintenance to the application. Below is the configuration.
RewriteCond /etc/apache/conf/MAINT -f
RewriteRule ^/foo$ /maintenance.html [R=302,L,NC]
This works just fine. But, I want to maintain a secret URI that I can use during the maintenance time. like https://dev.webrlc.com/maint-test.
For this I've made the following configuration.
RewriteCond /etc/apache/conf/MAINT -f
RewriteRule ^/foo$ /maintenance.html [R=302,L,NC]
RewriteCond /etc/apache/conf/MAINT -f
RewriteRule ^/maint-test$ /foo [PT]
This doesn't work & I can see it's pretty obvious. /maint-test will redirect to /foo and /foo inturn will redirect to /maintenance.html rather than fetching the /foo application from tomcat.
Could someone please help me on how to resolve it ? Really appreciate your help.
Add the P flag to use reverse proxy. Instead of pointing it to /foo, directly send the request to tomcat.
RewriteCond /etc/apache/conf/MAINT -f
RewriteRule ^/maint-test$ https://dev.apprlc.com:8080/foo [P]

Is it possible to rewrite url to another domain where the files are not located, using .htaccess?

A website is located at http://www.siteone.com
and I'd like to rewrite the url to something like http://www.anothersite.com/siteone or to a subdomain http://siteone.anothersite.com.
The website will be hosted only at http://www.siteone.com and no files will be moved or copied to anothersite.com.
Is it possible to do this using .htaccess or is there another way to do this?
EDIT (Below is what I've done in htaccess in my localhost and it does not seem to work). Not sure what I am doing wrong. I don't want to mess with the live site at this stage.
RewriteCond %{HTTP_HOST} /localhost/mysite [NC]
RewriteRule ^(.*)$ http://www.anothersite.com/siteone/$1 [L,P]
ProxyPassReverse /localhost/mysite http://www.anothersite.com/siteone/
As long as you have mod_proxy loaded, you can reverse proxy requests using the P flag in a rewrite rule. You can do this inside an htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?siteone.com$ [NC]
RewriteRule ^(.*)$ http://www.anothersite.com/siteone/$1 [L,P]
This will make it so when you visit http://siteone.com/some/path/, the request will get reverse proxied to http://www.anothersite.com/siteone/some/path/ and the contents from that request will be sent to the original request. This the URL in one's browser remains http://siteone.com/some/path/.
In order to handle things like redirects, you need to set a ProxyPassReverse so that the location headers get property rewritten:
ProxyPassReverse / http://www.anothersite.com/siteone/
See also, ProxyPassReverseCookieDomain and ProxyPassReverseCookiePath if the site at www.anothersite.com wants to set cookies.
Note: although the ProxyPass directive can only be used in vhost and server config, the ProxyPassReverse directives can actually be used in an htaccess file in conjunction with mod_rewrite.

Resources