Apache Mod-rewrite across domains? - apache

OK, I have a site, at www.domain.com. I added a web app on heroku and it has it Heroku URL and a custom domain. However, what I'd like to do is have it accessible via those two URL but on the www.domain.com site, I'd like to access that new server via www.domain.com/customapp. I figured I could do it through URL rewrite. But all the examples I see are doing the the other way, so is my idea possible? Is mod-rewrite the way to go?
Thanks.

Why don't you try setting up a reverse proxy for www.domain.com? Assuming you are using Apache 2.2, it's pretty easy to do if you have access to the httpd.conf or httpd-vhosts.conf file.
In your case I would add the following to your httpd.conf or httpd-vhosts.conf file.
ProxyRequests Off
ProxyPass /customapp/ <URL-to-Heroku-App>
ProxyPassReverse /customapp/ <URL-to-Heroku-App>
For more information, see the docs.
http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#proxypassreverse

Related

Redirect to another server site without changing domain name

I have two servers running Apache2, one with an associated domain name, let's say "www.home.com" and another one only known by its IP address, let's say 10.11.12.13.
On www.home.com I have three web sites, configured through aliases in apache.
I have http://www.home.com, http://www.home.com/school, http://www.home.com/work.
All these sites are on the server www.home.com.
On 10.11.12.13, I have only one site, accessible by http://10.11.12.13/wiki
How can I configure apache to have http://www.home.com/wiki working but transparently (not changing URL) call http://10.11.12.13/wiki site ?
In other words, the user shall only see www.home.com/wiki/xxxxx when he uses the wiki.
What I have done:
On www.home.com : i have added a wiki folder with nothing in it, and an alias for www.home.com/wiki to work properly.
Then I have tried to use mod rewrite to replace 10.11.12.13 by www.home.com but that does not work, and I am not even sure to do it the right way.
For your information, mod rewrite is configured and works properly on both servers.
Someone could please help me on that ?
Maybe mod rewrite is not the right solution ?
Thanks !
Sam
I finally found a solution : the mod_proxy along with tags.
The conf that worked for me:
<VirtualHost *:80>
[...]
ServerName www.home.com
<Location /wiki>
Allow from all
ProxyPass "http://10.11.12.13/wiki"
ProxyPassReverse "http://10.11.12.13/wiki"
</Location>
</VirtualHost>

Add www when accessing root domain, not using htaccess file

I have an apache server with some websites built in Wordpress, using vhosts.
The thing is that I have for all of them a configuration like:
ServerName site1.com
ServerAlias www.site1.com
When I access to Site1 through "site1.com" the URL changes to "www.site1.com". The same for Site2, Site3, etc. But for SiteN it's inverse. If I access to "siten.com" it keeps the URL and if you go to "www.siten.com" it changes to "siten.com".
I know I can change this using htaccess file, but my doubt is why some sites has a default and the new site has another default? All the htaccess have the same things and the vhost configuration is the same for all.
Thank you,
Done! The change should be implemented in Wordpress configuration, is not a htaccess issue

Apache webserver rewrite all URL's excluding some

I'm using apache httpd v2.2 server as a frontend proxy for our actual tomcat web server which hosts the Java web application.
I want to forward all urls received by apache webserver other than those having the prefix /product to tomcat.
I've tried the following set up in httpd.conf but it' doesn't seem to work
<VirtualHost *:6111>
ServerName localhost
RewriteEngine on
RewriteRule !^(/product($|/)) http://localhost:1234/$1
Alias /product /opt/productdoc
</VirtualHost>
I tried to follow Redirect site with .htaccess but exclude one folder but was not successful
Basically all http://localhost:6111/product urls should serve from hard drive (using alias)
Any other url should be forwarded to http://localhost:1234/<original-path>
You probably want to use something like mod_jk http://tomcat.apache.org/connectors-doc/webserver_howto/apache.html.
There are a ton of examples and tutorials and it should be pretty simple to setup and install. Now that you know the name of the connection technology, you should probably be able to find more information.
Using modjk also allows you to secure your tomcat server and keep the public off of it.

Apache ProxyPass doesn't work for multiple levels of path and enable proxypass for subdomains

I have two problems in setting Proxypass. I have setup the Proxypass in my Apache settings.
for example:
ProxyPass / http://www.domainname.com:8080/
ProxyPassReverse / http://www.domainname.com:8080/
I have the ROOT webapp in my tomcat to handle all the requests.
The following links work no problem:
http://www.domainname.com:8080/anypath1/anypathxxx
http://www.domainname.com:8080/anypath2/anypathxxx
but the followings to Apache do not work:
http://www.domainname.com/anypath1/anypathxxx
http://www.domainname.com/anypath2/anypathxxx
How do I fix the setting?
Another problem:
How do I setup wildcard proxypass for subdomains so that:
http://zzz.domainname.com/anypath1/anypathxxx proxypass to http://zzz.domainname.com:8080/anypath1/anypathxxx?
Thanks a lot in advance!!
I'am massively using Apache to loadbalance lots of Tomcats. I would strongly recommend mod_jk Apache Tomcat Connector for this case/job -> link. It is really easy to setup and truly stable!
Just install it from a repository, download binary (Windows) or build it from source.
Afterwards follow the quick start tutorial -> link
Also your second question (wildcards) could be solved this way.

Apache - Reverse Proxy and HTTP 302 status message

My team is trying to setup an Apache reverse proxy from a customer's site into one of our web applications.
http://www.example.com/app1/some-path maps to http://internal1.example.com/some-path
Inside our application we use struts and have redirect = true set on certain actions in order to provide certain functionality. The 302 status messages from these re-directs cause the user to break out of the proxy resulting in an error page for the end user.
HTTP/1.1 302 Found
Location: http://internal.example.com/some-path/redirect
Is there any way to setup the reverse proxy in apache so that the redirects work correctly?
http://www.example.com/app1/some-path/redirect
There is an article titled Running a Reverse Proxy in Apache that seems to address your problem. It even uses the same example.com and /app1 that you have in your example. Go to the "Configuring the Proxy" section for examples on how to use ProxyPassReverse.
The AskApache article is quite helpful, but in practice I found a combination of Rewrite rules and ProxyPassReverse to be more flexible. So in your case I'd do something like this:
<VirtualHost example>
ServerName www.example.com
ProxyPassReverse /app1/some-path/ http://internal1.example.com/some-path/
RewriteEngine On
RewriteRule /app1/(.*) http://internal1.example.com/some-path$1 [P]
...
</VirtualHost>
I like this better because it gives you finer-grained control over the paths you're proxying for the internal server. In our case we wanted to expose only part of third-party application. Note that this doesn't address hard-coded links in HTML, which the AskApache article covers.
Also, note that you can have multiple ProxyPassReverse lines:
ProxyPassReverse / http://internal1.example.com/some-path
ProxyPassReverse / http://internal2.example.com/some-path
I mention this only because another third-party app we were proxying was sending out redirects that didn't include their internal host name, just a different port.
As a final note, keep in mind that Firebug is extremely useful when debugging the redirects.
Basically, ProxyPassReverse should take care of rewriting the Location header for you, as Kevin Hakanson pointed out.
One pitfall I have encountered is missing the trailing slash in the url argument. Make sure to use:
ProxyPassReverse / http://internal1.example.com/some-path/
(note the trailing slash!)
Try using the AJP connector instead of reverse proxy. Certainly not a trivial change, but I've found that a lot of the URL nightmares go away when using AJP instead of reverse proxy.