We help IT Professionals succeed at work.
Get Started

RewriteRule with tomcat?

Last Modified: 2013-12-02
I have what must be a common problem. I want to rewrite "http" to "https". No big deal for apache, but I am using apache and tomcat. The following works fine for non-tomcat folders, e.g. http://www.mydomain.com/index.html

RewriteCond %{HTTPS} !on
RewriteRule ^/?(.*) https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

However, if the folder is under tomcat's webapps it doesn't work, even if I have an .htaccess file in the tomcat folder. So, I would like:

http://www.mydomain.com/mywebapp/somepage.jsp -> https://www.mydomain.com/mywebapp/somepage.jsp

as I said, I tried putting an .htaccess file with the above rewrite rule in both htdocs and mywebapp, but it didn't work. I also tried the following in httpd.conf:

<Location /mywebapp>
RewriteCond %{HTTPS} !on
RewriteRule ^/?(.*) https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

but that didn't work either. Strange, because I have another <Location> directive for authorization in another tomcat folder that *does* work.

I'm sure loads of people have run into this situation. How do I fix it?
Watch Question
Top Expert 2010
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE