LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 05-12-2013, 03:16 AM   #1
hesisaboury
Member
 
Registered: Dec 2010
Location: iran
Posts: 199

Rep: Reputation: 0
tomcat url redirect


hello,
i have http://example.com in tomcat now i want redirect all request to http://www.example.com/ ...
any suggestion
 
Old 05-12-2013, 08:08 AM   #2
DinoFly
Member
 
Registered: Nov 2007
Distribution: Fedora, CentOS,
Posts: 72

Rep: Reputation: Disabled
You can use HttpRedirectFilter you can find it http://www.zlatkovic.com/httpredirectfilter.en.html, or you can use UrlRewriteFilter as is httpd-s mod_rewrite,

or simply use index.jsp with a code:

<meta http-equiv="refresh" content="0;url=/somethink/index.jsp"/>
 
Old 05-13-2013, 12:14 PM   #3
u2013
LQ Newbie
 
Registered: Apr 2013
Posts: 14

Rep: Reputation: Disabled
via .htaccess

Quote:
Originally Posted by hesisaboury View Post
hello,
i have http://example.com in tomcat now i want redirect all request to http://www.example.com/ ...
any suggestion
In general, any kind of redirect of that kind can be done via .htaccess file that the http/https server references before pumping out data to the visitor.

I believe it would be the following. I am not 100% sure about the format, but I think it is correct. If wrong, then it will at least get you going in the needed direction.

Within .htaccess file in your sites http folder (commonly public_html, or /var/http)
Code:
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule ^$ "http\:\/\/www\.example\.com" [R=301,L]
 
Old 05-14-2013, 04:04 AM   #4
DinoFly
Member
 
Registered: Nov 2007
Distribution: Fedora, CentOS,
Posts: 72

Rep: Reputation: Disabled
Point is the apache tomcat is not aware of .htaccess. You can connect tomcat with httpd via connectors (mod_jk) but it is pointless doing it for url redirect.
 
Old 05-14-2013, 05:49 AM   #5
hesisaboury
Member
 
Registered: Dec 2010
Location: iran
Posts: 199

Original Poster
Rep: Reputation: 0
Thank You All,
I'm trying HttpRedirectFilter , but it does not work
<redirect-filter>
<redirect match="^(.*)$" target="www.example.com"/>
</redirect-filter>

in web.xml
<filter>
<filter-name>HttpRedirectFilter</filter-name>
<filter-class>com.zlatkovic.servlet.RedirectFilter</filter-class>
<init-param>
<param-name>configFile</param-name>
<param-value>/WEB-INF/redirect-filter.xml</param-value>
</init-param>
<init-param>
<param-name>reloadConfig</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>logRedirects</param-name>
<param-value>false</param-value>
</init-param>
</filter>

<filter-mapping>
<filter-name>HttpRedirectFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>


any suggestion
 
Old 05-14-2013, 01:49 PM   #6
DinoFly
Member
 
Registered: Nov 2007
Distribution: Fedora, CentOS,
Posts: 72

Rep: Reputation: Disabled
and have you made the configuration file that you are calling?

Quote:
/WEB-INF/redirect-filter.xml
does it contain the info what to redirect, where to redirect?
 
Old 05-14-2013, 11:29 PM   #7
hesisaboury
Member
 
Registered: Dec 2010
Location: iran
Posts: 199

Original Poster
Rep: Reputation: 0
in my redirect-filter.xml

<!DOCTYPE redirect-filter PUBLIC
"-//zlatkovic.com//DTD RedirectFilter 2.0//EN"
"http://www.zlatkovic.com/dtd/redirect-filter-2.0.dtd">

<redirect-filter>
<redirect match="^(.*)$" target="https://www.example.com"/>
</redirect-filter>

Last edited by hesisaboury; 05-14-2013 at 11:30 PM.
 
Old 05-15-2013, 10:55 AM   #8
DinoFly
Member
 
Registered: Nov 2007
Distribution: Fedora, CentOS,
Posts: 72

Rep: Reputation: Disabled
I don't see any problem as long as you added to /WEB-INF/web.xml

Code:
<filter>
<filter-name>HttpRedirectFilter</filter-name>
<filter-class>com.zlatkovic.servlet.RedirectFilter</filter-class>
<init-param>
<param-name>configFile</param-name>
<param-value>/WEB-INF/redirect-filter.xml</param-value>
</init-param>
<init-param>
<param-name>reloadConfig</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>logRedirects</param-name>
<param-value>false</param-value>
</init-param>
</filter>

<filter-mapping>
<filter-name>HttpRedirectFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
and on the /WEB-INF/redirect-filter.xml

Code:
<!DOCTYPE redirect-filter PUBLIC
"-//zlatkovic.com//DTD RedirectFilter 2.0//EN"
"http://www.zlatkovic.com/dtd/redirect-filter-2.0.dtd">

<redirect-filter>
<redirect match="^(.*)$" target="https://www.example.com"/>
</redirect-filter>
I can see you matching anything that has at least 1 character and redirecting it on https://www.example.com
Code:
<redirect match="^(.*)$" target="https://www.example.com"/>
Is your JRE > 1.6.0?
Have you installed the redirectfilter-2.0.jar file to /WEB-INF/lib ?
Off course it needs to restart the tomcat.

I don't see any reason why it wont work. Maybe you should ask the developers it is on their web the contact info.

And if you manage to make it work than post it back here for others who have similar issue.

Regards
 
Old 05-15-2013, 11:06 AM   #9
DinoFly
Member
 
Registered: Nov 2007
Distribution: Fedora, CentOS,
Posts: 72

Rep: Reputation: Disabled
Emm try to put "/" in your code

Code:
<redirect match="^(.*)$" target="https://www.example.com"/>
it should look:

Code:
<redirect match="^/(.*)$" target="https://www.example.com"/>
Meaning anydirectory .

Is "https://www.example.com" hosted on your serer aswell? if so put the exact dir's to be redirected.

example:
Code:
<redirect match="^/firstdir(.*)$" target="/seconddir$1"/>
where "/firstdir" is the dir of your http://example.com and "/seconddir" to https://www.example.com
I don't know if it actually works with url since it only has examples with working directories.
 
Old 05-17-2013, 05:20 AM   #10
hesisaboury
Member
 
Registered: Dec 2010
Location: iran
Posts: 199

Original Poster
Rep: Reputation: 0
i removed port 80 tp 433 redirect in server.xml
when i use <redirect match="^/(.*)$" target="https://www.example.com"/>
in browser it will be http://example.com/https://www.example.com/

Last edited by hesisaboury; 05-17-2013 at 08:35 AM.
 
Old 05-17-2013, 09:01 AM   #11
hesisaboury
Member
 
Registered: Dec 2010
Location: iran
Posts: 199

Original Poster
Rep: Reputation: 0
Finally
by changing /ROOT/index.html and editing URL , to htts://www.example.com/login ... i solved my Redirection Problem....of course till now i don't see any problem....

Thanks ALL
 
Old 05-17-2013, 11:57 AM   #12
hesisaboury
Member
 
Registered: Dec 2010
Location: iran
Posts: 199

Original Poster
Rep: Reputation: 0
Sorry ... It's NOT OK
when i type IP instead or domain name .. it goes to bad SSL ...what the ...

Any Suggestion
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Redirect a tomcat application URL and port using apache. sudheshpn Linux - Software 5 06-17-2011 03:51 PM
Cannot Redirect URL to another URL when the link is down with Squid marx_long Linux - Newbie 1 06-13-2010 08:59 PM
how to redirect url in apahce or tomcat? jimmyjiang Red Hat 2 11-12-2007 11:14 AM
redirect url munna_dude Linux - Software 2 02-15-2007 12:18 AM
url redirect Present Linux - Networking 4 01-26-2007 09:08 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 11:28 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration