How can I forward requests to http://server:port to http://server:port/app - apache

I'm adding a new service to one of the servers I am currently running, and I'm having troubles getting both applications to run nicely.
Currently I have an web application running on http://server.com:8080/ and I need to be able to forward any of those requests to http://server.com:8080/app (or something similar). I've tried to do some ProxyPass and ReverseProxyPass configurations but I do not understand apache2 well enough to understand what is going wrong.
Can someone provide me with information on how to accomplish this?

You may use a rewrite rule like the following:
RewriteEngine On
RewriteRule ^/(.*) ^/app/$1

Related

Apache: .htaccess vs vhost conf file for blocking URLs

I need to block some uld URLs that are generating a lot of traffic in my web server (Apache). For example to block all the requests like https://example.com/xxxxxx/
I Can't do that with IPtables so I am using mod_rewrite with a rule in my .htaccess
That is still consuming a lot of resources and I am wondering if there is a better way to block the request before reaching Apache. Or another most efficient way to do it within Apache. For example, I heard that parsing .htaccess files consumes resources so not sure if using the vhost .conf file can help or it is really the same...
Any advice on how can I block requests using the URL?
Thank you experts!
Certainly distributed configuration files consume more load than a single, central and static configuration. But the differences are not like day and night. The issue with a distributed configuration is more the effort to keep the overview, to maintain it.
If you can keep those requests away from the http server at all you certainly will see more difference. You could consider using a frontend server. Something like nginx or HAProxy that acts as a gate keeper and only forwards those requests you actually want to respond to. This makes little sense on a single system though, you'd need two separate cloud services or even systems for that.
The best approach would be to add something like this to your httpd / vhost.conf file:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/xxxx$
RewriteRule ^ - [F]
Every call to /xxxx would result in mod_rewrite to return a 403 response.
Make sure to place those rules into the according vhost tag.

Rewrite dynamic url htaccess apache

I would need to perform a redirect by extrapolating a part of the url and then creating the new one.
Specifically, I have to redirect:
https://(part to be extracted).montecoasp.it
up:
https://(extracted part).montecosrl.it
PLEASE NOTE: The part to be extracted may not even be there.
Can anyone tell me what to write in the htaccess file? Should you use RewriteUrl, RedirectMatch or what? Thank you.
I assume this is what you are looking for:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(\w+\.)?montecoasp\.it$
RewriteRule ^ https://%1montecoasp.it%{REQUEST_URI} [R=301,END]
You can implement such rule in a distributed configuration file, but you should prefer to use the static http server's host configuration.
Obviously the rewriting module needs to be loaded into the http server for this. And if you want to use a distributed configuration file (".htaccess"), then you need to enable those too...
In general it is a good idea to start out with a R=302 temporary redirection and only to change that to a R=301 permanent redirection once everything is sorted out. That prevents nasty caching issues...
You definitely should start reading the documentation of the tools you are using. You want to learn how things work, you do not just want to blindly copy things. As typical for OpenSource software the apache documentation is of excellent quality and comes with great examples:
https://httpd.apache.org/docs/current/howto/htaccess.html
https://httpd.apache.org/docs/current/mod/mod_rewrite.html

APACHE multiple url routing

thanks for clicking my question! <3.
Basically, I've tried to create a basic routing in my apache httpd installation, it looks like this:
RewriteEngine on
RewriteRule social/user social/profile.php
But if I want to create another routing to make it (for example) "social/user/sarah_thecowboy" it will open "profile.php" anyway, even if there is a rule getting a parameter. Is there a way I can do something like that?

how to configure phabricator with a non root url?

I am trying to install phabricator behind apache http server. The problem is that i would like to have an url like
http://myserver.fr.xxxx/phabricator and not http://myserver.fr.xxxx/
i have tried several configuration in apache but i am not able to have phabricator working correctly (alias,redirect).
Is there any solution with a tricky apache configuration or phabricator future release to handle this ?
This is not supported, and we do not plan to support it. The install documentation should probably make this more clear, although it is mentioned in the Configuration Guide:
You can either install Phabricator on a subdomain (like
phabricator.example.com) or an entire domain, but you can not install
it in some subdirectory of an existing website.
We don't plan to support this because support would be complex and have security implications, and only a tiny number of very small installs would benefit.
I'm using the following in the root of my apache config file:
RewriteEngine on
RewriteRule ^/phabricator/rsrc/(.*) - [L,QSA]
RewriteRule ^/phabricator/favicon.ico - [L,QSA]
RewriteRule ^/phabricator/(.+)$ /phabricator/index.php?__path__=$1 [B,L,QSA]
However, I can't fully test it because my computer doesn't seem to think ./bin/storage is a valid executable so I can't setup the database behind it.
It seems to work so far, but I'm not sure if the phabricator php code will just work or of it will need some modification as well. (when I visit MYHOST/phabricator/index.php, I get a phabricator error page related to the missing mysql setup)

Escaping spaces in mod_rewrite

I have the following Apache mod_rewrite rule:
RewriteRule ^(.*) http://127.0.0.1:4321/$1 [proxy]
This works great; Apache forwards all requests to the CherryPy server I have running on the same machine.
Unfortunately, I'm having some problems with paths which have a space. If I make a request for /Sites/some%20site/image.png then Apache makes a request to CherryPy for /Sites/some site/image.png which messes up CherryPy.
Is there a way to specify in my RewriteRule that I'd like to re-escape spaces in the URL before forwarding the request to CherryPy?
EDIT: I found a reference to something that might help, but I went ahead and ducked the problem by replacing the spaces with underscores and having CherryPy do a conversion before serving the files.
I'd still like to know a better solution if anyone has one; unfortunately I'm on a deadline and don't have time to muck around with this myself at the moment. I may return to this later and post further updates when I find the time.
Please see http://tools.cherrypy.org/wiki/ModRewrite#Bewaretheencodingbug for the best known solution.