Java app loads single url only after deployed - .htaccess

I have tested my Java app in local developed using jsp and servlets.
I have a domain and I copy the war in this domain. Now I am able to access this app as http://mdomain.com:8080/myApp without issues.
Now, I want to make this app available while hitting http://mdomain.com.
So, I configured the .htaccess file for this domain as follows,
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mydomain.com
RewriteRule ^(.*)$ http://mdomain.com:8080/myApp/ [P]
Now, I am able to see the home page when hittng http://mdomain.com.
While I am hitting submit button, the page is loading only the home page and no respective pages displayed.
I am using apache tomcat7. Put my war in webapps.
What I am missing here?
May I copy the myApp folder to public_html folder.

If mod_proxy is enabled then you can use:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mydomain\.com$ [NC]
RewriteRule ^(.*)$ http://mdomain.com:8080/myApp/$1 [P]
Note use of $1 which is back-reference of captured value in RewriteRule

Related

How to redirect root domain to subfolder (with https) and rest of addon domains to subfolders (without https)

How to redirect root domain to subfolder (with HTTPS) and rest of other addon domains to subfolders (without HTTPS).
Currently I have this .htaccess in root which redirects with HTTPS to the-main-subfolder ok. But my other addon domain, say domain2 also gets redirected to the-main-subfolder.
I would like to redirect domain2 to the-domain2-subfolder without HTTPS.
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RedirectMatch ^/$ /the-main-subfolder/
I am not sure if this code is correct as it might me using a wildcard. I got this code from searching on net but there are so many suggestions that I am confused now!
In summary: My main hosting account in root should go to https://www.domain1.co.uk/the-main-subfolder when user types in domain1.co.uk in browser and my addon domain http://domain2.co.uk should go to http://www.domain2.co.uk/the-domain2-subfolder.
You can use additional RewriteConds to define specific redirections:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^example.org$
RewriteRule ^ https://%{HTTP_HOST}/the-main-subfolder%{REQUEST_URI} [L,R=301,QSA]
RewriteCond %{HTTP_HOST} ^example1\.org$
RedirectRule ^(.*)$ /example1\.org-subfolder/$1 [L,QSA]
RewriteCond %{HTTP_HOST} ^example2\.org$
RedirectRule ^(.*)$ /example2\.org-subfolder/$1 [L,QSA]
RewriteCond %{HTTP_HOST} ^host1\.example\.org$
RedirectRule ^(.*)$ /host1\.example\.org-subfolder/$1 [L,QSA]
RewriteCond %{HTTP_HOST} ^host2\.example\.org$
RedirectRule ^(.*)$ /host2\.example\.org-subfolder/$1 [L,QSA]
I added a few examples to demonstrate the redability of explicit implementation and that you can do that for both, separate domains and hostnames (sometimes incorrectly called "subdomains"). I would always prefer such explicit notation over generic approaches since you can individually modify things, for example for testing or debugging purposes. Except if you are in a mass hosting situation obviously, then a database based approach makes sense.
Note that the redirection for what you call the "root domain" (example.org here) has a second RewriteCond now. Both conditions are AND-combined per default.
For safety you probably also want to add some more rules to redirect requests to something like https://example.org/host1.example.org-subfolder to the specific domain name, since according to your description you are limited to a single file tree in your hosting account. Same for request to http://test1.example.org/test1.example.org-subfolder/... to eliminate the literal folder name.
Oh, and a warning: the above syntax works for .htaccess style files only. If you have access to the real host configuration then you should always prefer to place such rules in there. However you need a slightly changed syntax then. .htaccess style rules are notoriously error prone, hard to debug and they really slow down the http server. They are only offered as a last option for those without access to the host configuration.
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^domain1.co.uk$
RewriteRule ^ https://%{HTTP_HOST}/the-main-subfolder%{REQUEST_URI} [L,R=301,QSA]
Thanks #arkascha - Everything now works as expected with the above code. I suppose we do not need to mention so called add-on domains here at all because cPanel handles the sub-directories for them internally when we add subsequent domains on the hosting package (i.e. addon domains)!
Just to update that my previous solution partially works as it has few niggles/bugs. So went back to the drawing board and suddenly realised I was unnecessarily trying too hard!!
Deleted the old htaccess file first and followed instruction below..
The solution is already provided by cPanel in something called "Redirects" in Panel Icons.
I just had to enter everything in user interface text boxes like choose domainname = "domain1", old folder = "\", new folder = "https://www.domain1.co.uk/the-main-subfolder" - And just click create the redirect. In doing so it creates a .htaccess file itself automatically. I am sharing this below:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain1\.co\.uk$ [OR]
RewriteCond %{HTTP_HOST} ^www\.domain1\.co\.uk$
RewriteRule ^/?$ "https\:\/\/www\.domain1\.co\.uk\/the-main-subfolder\/" [R=301,L]

.htaccess redirect but show different URL

I want my site to act like this. If user inputs site.cz it should be redirected to site.eu/?lang=cs but the user should still see site.cz. Right now I have the following htaccess file:
RewriteCond %{HTTP_HOST} site\.cz [NC]
RewriteCond %{REQUEST_URI} ^/$
Rewriterule ^(.*)$ http://site.eu/?lang=cs [L,R=301]
which works great and redirects only .cz request (dont do anything with .eu requests) but it displays .eu/?lang=cs in final. Problem is that I dont only want to display site.cz all the time but also links like site.eu/folder1/file1/?lang=cs should be redirected to site.cz/folder1/file1/
Any ideas how to accomplish this?
Thanks in forward
Are you using XAMPP or a web host? Upon testing, URL rewriting isn't working in XAMPP.. Anyway, you can try to check this, just make sure that your two sites are hosted by the same web hosting account:
RewriteCond %{HTTP_HOST} site\.cz [NC]
RewriteRule ^(.*)$ http://site.eu/$1?lang=cs [P,L]
But it looks like your sites aren't hosted by the same hosting account as what you've said:
when I use [P] flag I get an error "Following URL was not found on this server" – horin

Mirror a specific path to another url using .htaccess

I would like to use two separate url's, pointing to two separate websites, using one hosting and one backend.
So far there's only one website (I'll name it domain1.com).
And there's already some mod-rewriting used.
redirecting www.domain1.com to domain1.com
RewriteEngine On
RewriteCond %{http_host} ^www.domain1.com$
RewriteRule ^(.*)$ http://domain1.com/$1 [R=301,L]
using nice urls, so domain1.com/news/item points to domain1.com/index.php?/news/item
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index.php)
RewriteRule ^(.*)$ index.php?/$1 [L]
What I would like to achieve are the following things
domain1.com/specific_folder_name/123456789 should point to domain2.com/123456789 just for cosmetics
domain2.com/123456789 should run /index.php?/specific_folder_name/123456789
It should result in this:
when surfing to domain1.com/param1/param2, the server gives you index.php?/param1/param2
whan surfing to domain1.com/specific_folder_name/123456789 you get redirected to domain2.com/123456789 and the server gives you /index.php?/specific_folder_name/123456789
I hope this is clear enough...
I believe you can get this done via ProxyPass Directive
This directive allows remote servers to be mapped into the space of
the local server; the local server does not act as a proxy in the
conventional sense, but appears to be a mirror of the remote server.
The local server is often called a reverse proxy or gateway. The path
is the name of a local virtual path; url is a partial URL for the
remote server and cannot include a query string.
more details

Point External Domain and Sub Directories to Site's Folder

A lot of pages in our site uses an old subdomain for images, css and javascript files. I inherited the project from newbie developers and they didn't use any common design template. The result are hundreds of pages with static references to contents an examples are:
http://static.foo.bar/css/sample.css
http://static.foo.bar/brochure/css/sample.css
http://static.foo.bar/company/newsletter/js/common.js
http://static.foo.bar/images/version2/header.jpg
...and hundreds of other locations. I need to point them all to the main domain instead of the subdomain without creating rules for each of these on the .htaccess file. So:
http://static.foo.bar/css/sample.css
should point to:
http://www.foo.bar/css/sample.css
http://static.foo.bar/brochure/css/sample.css
should point to:
http://www.foo.bar/brochure/css/sample.css
http://static.foo.bar/company/newsletter/js/common.js
should point to:
http://www.foo.bar/company/newsletter/js/common.js
http://static.foo.bar/images/version2/header.jpg
should point to:
http://www.foo.bar/images/version2/header.jpg
I know this is possible only I'm not a server guy. Any help would be very much appreciated.
Create an .htaccess file in the document root with this content:
Add this to your server configuration, %{HTTP_HOST} check does not work from .htaccess:
<IfModule mod_rewrite.c>
# bad matching: RewriteCond %{HTTP_HOST} !^static\.foo\.bar [NC]
#
# correction, matching everything other than www.foo.bar :
RewriteCond %{HTTP_HOST} !^www\.foo\.bar$ [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*) http://www.foo.bar/$1 [L,R]
</IfModule>
See http://httpd.apache.org/docs/2.0/misc/rewriteguide.html#url
UPDATE:
Giving it a second though, if it's hosted on the same server, just add
ServerAlias static.foo.bar
to the www.foo.bar configuration to serve up the static content, too.
UPDATE #2 based on feedback:
This should work (works on my pc) in the .htaccess file, this redirects all requests coming to static.foo.bar/* to www.foo.bar/* :
RewriteCond %{HTTP_HOST} ^static\.foo\.bar [NC]
RewriteRule ^(.*)$ http://www.foo.bar/$1 [R,L]
And no, the ServerAlias command only works from a VirtualHost configuration:
http://httpd.apache.org/docs/2.2/mod/core.html#serveralias

ISAPI_Rewrite 3.0 ... Noob ... how to get started? just installed

just installed v3 lite to try it out before getting full version.
i got the follwing in .htaccess file in the root folder of the .net web app
RewriteEngine On
RewriteCond %{HTTPS} (on)?
RewriteCond %{HTTP_HOST} ^zzzz-wildcard\.domain\.com
RewriteRule ^(.*)$ http://domain.com/zzzz-wildcard$1 [R]
problem is it doesn't do anything. i got the wildcard set up on iis so that
test.domain.com is served just as domain.com would be.
What i want to achieve is to serve any sub-domain user1.domain.com as domain.com/zzzz-wildcard
from what i got so far even explicity supplying zzzz-wildcard.domain.com still serves the default.aspx of the domain.com instead of domain.com/zzzz-wildcard/default.aspx
please help. i have never worked with isapi rewrite so i have no clue how to go about this.... right now as it stand it doesn't really do anything. can't say i'm good with regular expressions either :(
When opening ISAPI_Rewrite Manager and selecting my domain.com from the list of iis websites it says No properties available for this node.
******** EDIT ********
after some more looking around i found out that lite version doesn't support .htaccess so only httpd.conf file that works globally. So anyway i modified the httpd.conf file instead and it now works..
however it just redirects zzzz-wildcard.domain.com to domain.com/zzzz-wildcard
Is there a way to keep the url intact and not redirect? but still serve the pages from domain.com/zzzz-wildcard ?
finally solved after looking around other answers on stackoverflow
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(.*?)\.domain\.com$ [NC]
RewriteRule (.*) /zzzz-wildcard/%{REQUEST_URI} [NC]

Resources