Apache 2.4.43 is changing my url "?" to "%3F" - apache

I have just deployed apache 2.4 and i defined a virtual host tag to redirect to a specific url.
The problema is my url includes a "?" character and Apache change it to "%3F".
Here is my actual Virtual host configuration tag:
<VirtualHost *:80>
ServerName http://app2x.example.com
RewriteEngine On
ProxyRequests Off
ProxyPreserveHost On
ErrorLog "logs/app2x.example.com-error.log"
CustomLog "logs/app2x.example.com.log" common
ProxyPass /sib http://172.168.100.3:9097/sib/f?p=103:1
ProxyPassReverse /sib http://172.168.100.3:9097/sib/f?p=103:1
</VirtualHost>
as you can see there is a "?" character in url, but when i test it i get next error :
/sib/f%3Fp=103:1 start: 2020-04-21T17:37:53.992Z duration: 16ms
URLMappingNotFoundException [statusCode=404, reasons=[The request could not be mapped to any database. Check the request URL is correct, and that URL to database mappings have been correctly configured]]
I have tested with this url:
ProxyPass /sib http://172.168.100.3:9097/
and work just fine, but i need to redirect to full shown url
I am Using windows 2019 server STD Edition 64 bits with Apache 2.4.43 and the URL i am pointing to is in another similar machine.
i am new using Apache and have not found an answer on google to solve it, any help will be appreciated.
Thanks

i have just fixed my issue (after a couple of days googling and trying), i made it work.
I have to use RewriteRule as follows:
1.) my httpd-vhosts.conf file looks like this:
<VirtualHost *:80>
ServerName http://app2x.example.com
RewriteEngine On
RewriteRule ^/sib$ sib/f?p=103:1 [R=301] # => everything that contains "/sib" redirect to url: "sib/f?p=103:1"
RewriteRule ^/([a-zA-Z0-9]+)$ sib [R=301] # => everything that contains "/any letter or number" redirect it to sib, that, at same time, will redirect it to url: "sib/f?p=103:1"
ProxyRequests Off # => so the server does not work as a normal proxy
ProxyPreserveHost On # => important to keep url format from oracle apex server, if not, will display errors when using the app because apache will change the deeper url's
ProxyPass / http://172.168.100.3:9097/ # => important do not forget this last "/"
ProxyPassReverse / http://172.168.100.3:9097/
</VirtualHost>
2.) don't forget to enable mode rewrite line in file: httpd.conf, so the previous config can work
Enable this line => LoadModule rewrite_module modules/mod_rewrite.so
Thats it!,
happy coding
Majv

Related

Apache Reverse Proxy not Working with Grafana

I'm pulling my hair out because it must be something simple.
I've setup Grafana to run through a subdomain via proxy which works fine. I'm doing basic authentication as well to login to Grafana, this is my apache config:
<VirtualHost *:80>
ServerAdmin webmaster#example.co
ServerName example.co
ServerAlias www.example.co
DocumentRoot /var/www/example.co/public_html/
ErrorLog /var/www/example.co/logs/error.log
CustomLog /var/www/example.co/logs/access.log combined
<Location "/application">
AuthType Basic
AuthName "Graphs Login"
AuthUserFile /var/www/example.co/members/.htpasswd
Require valid-user
ProxyPass http://localhost:3000/
</Location>
ProxyPassReverse /application http://example.co:3000/
</VirtualHost>
And my config in grafana.ini
# The public facing domain name used to access grafana from a browser
domain = example.co
# Redirect to correct domain if host header does not match domain
# Prevents DNS rebinding attacks
;enforce_domain = false
# The full public facing url you use in browser, used for redirects and emails
# If you use reverse proxy and sub path specify full url (with sub path)
root_url = %(protocol)s://%(domain)s:%(http_port)s/application/
I've also tried to do this with a 301 redirect:
Redirect 301 /application http://example.co/application/
<Location "/application/">
AuthType Basic
AuthName "Graphs Login"
AuthUserFile /var/www/example.co/members/.htpasswd
Require valid-user
ProxyPass http://localhost:3000/
ProxyPassReverse http://localhost:3000/
</Location>
The ProxyPass to the domain works fine, however if I use the IP address it doesn't go to the domain, but rather it tries to load it as IP:3000/application which then gives a Grafana error (Blank page with {{alert.title}})
Any idea what I am doing wrong and how I can redirect the IP:3000 to DOMAIN:3000 such as the ProxyPass is doing with Reverse Proxy?
I'm using Ubuntu 12.04
I've done all sorts of things such as adding trailing slashes, removing them from both apache and from grafana configs, i've been using incognito everytime to ensure there is no caching and I just can't get it to work in Reverse Proxy where I'm trying to redirect the IP to the domain that I've set in Grafana and ProxyPass.
Please help!
I am not 100% sure if this may be the issue. However let's give it a try: Try removing the slashes after the ProxyPass directives:
ProxyPass /application http://localhost:3000
ProxyPassReverse /application http://localhost:3000
Grafana seems to be very picky with regard to those slashes. I had several issues with those little buggers :) I will explain the details further below. A very simple working setup (without specific authentication though) looks like this:
Apache
<VirtualHost *:443>
ServerName example.co
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
# grafana
ProxyPass /grafana http://thorin:3000
ProxyPassReverse /grafana http://thorin:3000
</VirtualHost>
Grafana
domain = example.co
root_url = %(protocol)s://%(domain)s/grafana
Explanation: Slashes
Next I explain the reason for the unexpected behavior as far as I understood it. For completeness sake I am also adding an issue I had with certain rewrite rules in addition to the proxy setup.
Proxy
So what happens if you keep the slashes?
# WRONG!
ProxyPass /application http://localhost:3000/
ProxyPassReverse /application http://localhost:3000/
In this case, the response you get from Grafana is a ugly page showing {{alert.title} and a bunch of other unformated HTML. The reason for this is that Grafana can not load certain resources:
http://example.co/application/public/build/grafana.dark.css?v5.2.4
http://example.co/application/public/build/vendor.4f5454f867a0cc2fe8dd.js
However, you proxy settings work correctly, right? Well, partially. They have that tiny slash / resulting in the following lookups on your Grafana installation:
http://localhost:3000//public/build/grafana.dark.css?v5.2.4
http://localhost:3000//application/public/build/vendor.4f5454f867a0cc2fe8dd.js
Notice the extra slash / after http://localhost:3000. Try calling those URLs. They do not work. This is Grafana being very picky about URLs :) Thus, removing the extra slashes from your Apache config will do the trick.
At least that is what I came up with so far:)
Rewrite
No, rewrite rules. In our setup we have Jekyll setup in another subpath, say http://example.co/jekyll where we use relative URLs to access resources. This requires a slash at the end of each URL. We solved this by adding following rewrite rule in Apache (there may be better solutions for this; if you have suggestions please let me know):
# add trailing slashes to support relative URLs
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !(.*)\.[a-zA-Z0-9]+$
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ $1/ [R=301,L]
This resulted in some funny effects on Grafana:
we could not log in
the admin/admin account worked however it got stuck at changing the default password
all data sources were gone
Turns out that Grafana did not like the redirects and slash policy we introduced here. The solution was to only enable this rewrite rule for applications that needed it:
# add trailing slashes to support relative URLs
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !(.*)\.[a-zA-Z0-9]+$
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteCond %{REQUEST_URI} ^jekyll.*$
RewriteRule ^(.*)$ $1/ [R=301,L]
Let me know if this helps :)

URL Rewrite in httpd.conf

I have a redirect setup on my Apache server within the httpd.conf file that redirects all traffic to "server.mydomain.com" to https://server.mydomain.com/uri. Unfortunately, some users will enter https before the URL and it does not redirect, instead they get Apache error page. I want to know how can I get users who input https before the URL to be redirect to https://server.mydomain.com/uri. I believe I may have to do a rewrite but I'm not sure or know how to go about doing it. I've research about rewrite and found it should be done in the .htaccess file but when I read Apache best practice they state it should not be done within .htaccess file for security and performance. Instead, it should be done within the config file. Since the redirection is working within the httpd.conf file, I would like to incorporate the rewrite there as well. I presume that is the correct according to Apache website. My issue is how do I go about doing this within that file. I've included the file information below. Any assistance is greatly appreciated. The server is using Tomcat 7 with Apache 2.2.15.
httpd.conf file:
</IfModule>
#
ProxyPass /uri/fbs-ws ws://server.mydomain.com:8081/uri/fbs-ws
ProxyPassReverse /uri/fbs-ws ws://server.mydomain.com:8081/uri/fbs-ws
</IfModule>
<VirtualHost *:80>
ProxyPass /uri http://server.mydomain.com:8080/uri
ProxyPassReverse /uri http://server.mydomain.com:8080/uri
Redirect permanent / https://server.mydomain.com/uri
</VirtualHost>
Did you try creating a vhost for 443 and switching to http there via Rewrite?
<VirtualHost *:443>
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI}
</VirtualHost>

Redirect but keep the domain the same

I have an owncloud server, and I would like to setup a second short domain, to keep the shared links short.
lets say we've the longdomain.com and short.com
Heres is my httpd lines
<VirtualHost *:80>
ServerAdmin email#adderss.com
DocumentRoot /var/www/dir/public_html
ServerName short.com
ServerAlias www.short.com
RewriteEngine on
RewriteRule ^/([A-Za-z0-9]{4,12})$ https://www.long.domain.com/public.php?service=shorty_relay&id=$1 [QSA,L]
ErrorLog /var/www/dir/error.log
</VirtualHost>
With the current lines, short.com redirects to exactly where I need, but I would like this redirect to be on the background and keep the short domain on the user's browser.
How can I do this?
Update:
with this in my short domain virtual host I can visit my owncloud using the short domain.
For example: short.com/index.php/apps/files/
the long domain is vanished. I think Im one step forward now.
ProxyPass / https://www.long.domain.com
ProxyPassReverse / https://www.long.domain.com
The next step is to use the the regex so I can load only shorty id links.
How can I combine the rewrite regex above with the proxypass.
I've tried ProxyPassMatch butI havent figured out how to use it properly
Any ideas?
If you can't make the same content addressable by short.com, short.com can proxy to the long domain by loading mod_proxy, mod_proxy_http, and changing your rewrite flag from R to P.

Can I configure Apache on my laptop to forward to real site for all requests except one?

I want to run some local tests on a site I have. The site is accessible at www.mysite.com. I want one particular file to be fetched from my local machine. I thought I could maybe achieve this by
installing Apache locally
adding 'localhost www.mysite.com' to my hosts file
configure Apache to forward all requests to www.mysite.com except for requests for the particular file www.mysite.com/myapp/myfile.css, which should be served from the Apache web server running locally.
Firstly I am not sure whether that set-up would work - in the case where a file is requested that is not my special case, the request would be forwarded to www.mysite.com/... , but would that then (because of the entry in my hosts file) go back to my local Apache server and into some infinite loop?
Secondly (and only relevant if the above is not true), how would I configure Apache to do that? I guess I need a ProxyPass but I'm having trouble figuring out exactly what.
Thanks for any help.
Paul
I don't think you'll be able to do this the way you're suggesting as you'll never be able to perform a lookup to proxy to www.mysite.com if you've defined it as localhost.
You could create another domain in your hosts file, say local.mysite.com and host the desired website files there and proxy everything else to www.mysite.com:
<VirtualHost *:80>
ServerName local.mysite.com
DocumentRoot ...
<Directory ...>
...
</Directory>
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/myapp/myfile.css
RewriteRule ^(.*)$ http://www.mysite.com/$1 [P]
</VirtualHost>
Or if www.mysite.com works directly using the IP (i.e. not via virtual hosting) you could point localhost to mysite.com and use the real IP in the rewrite proxy.
<VirtualHost *:80>
ServerName www.mysite.com
DocumentRoot ...
<Directory ...>
...
</Directory>
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/myapp/myfile.css
RewriteRule ^(.*)$ http://1.2.3.4/$1 [P]
</VirtualHost>

Apache multiple URL to one domain redirect

For the last two day, I've been spending a lot of time to solve my problem, maybe someone can help me.
Problem: I need to redirect different url's to one tomcat webbase-dir used for artifactory.
following urls should point to the tomcat/artifactory webapp:
maven-repo.example.local ; maven-repo.example.local/artifactory ; srv-example/artifactory
Where maven-repo.example.local is the dns for the server-hostname: "srv-example"
I'm accessing the tomcat app through the JK_mod module. The webapp is in the ROOT directory
This is what I've got so far:
<VirtualHost *:80>
#If URL contains "artifactory" strip down and redirect
RewriteEngine on
RewriteCond %{HTTP_HOST} ^\artifactory\$ [NC]
# (how can I remove 'artifactory' from the redirected parameters? )
RewriteRule ^(.*)$ http://maven-repo.example.local/$1 [R=301,L]
ServerName localhost
ErrorLog "logs/redirect-error_log"
</VirtualHost>
<VirtualHost *:80>
ServerName maven-repo.example.local
ErrorLog "logs/maven-repo.example.local-error.log"
CustomLog "logs/maven-repo.example.local-access.log" common
#calling tomcat webapp in ROOT
JkMount /* ajp13w
</VirtualHost>
The webapp is working with "maven-repo.example.local", but with "maven-repo.example.local/artifactory" tomcat gives a 404 - "The requested resource () is not available."
It seems that the mod_rewrite doesn't have taken any effect, even if I redirect to another page, e.g google.com
I'm testing on windows 7 with maven-repo.example.local added in the "system32/drivers/hosts" file
Thanks in advance!
Thanks a lot for your hint #PHP-Prabhu
a simple:
RedirectPermanent /artifactory /.
in the apache httpd.conf did the trick!
First, all Redirects are processed before Aliases are processed, and therefore a request that matches a Redirect or RedirectMatch will never have Aliases applied. Second, the Aliases and Redirects are processed in the order they appear in the configuration files, with the first match taking precedence
Please see this URL
http://httpd.apache.org/docs/2.1/mod/mod_alias.html