0

I have a problem trying to rewrite the root of my web from mywebsite.com/mywebsite to www.mywebsite.com/mywebsite.

The problem is related to the use of mod_proxy to invoke Tomcat

File proxy.conf

<ifmodule mod_proxy.c>
    ProxyRequests Off
    ProxyPreserveHost On

    <proxy *>
       AddDefaultCharset off
       Order deny,allow
       Allow from all
    </proxy>

    ProxyVia On 
    ProxyPass /mywebsite ajp://91.222.222.222:8009/mywebsite
    ProxyPassReverse /mywebsite ajp://91.222.222.222:8009/mywebsite

    <location miaplicacion>
        Order allow,deny
       Allow from all
    </location>
</ifmodule>

File .htaccess

RewriteCond %{HTTP_HOST} !^www.mywebsite.com [NC] 
RewriteRule ^(.*)$ http://www.mywebsite.com/$1 [NC,L,R=301]

The point is that the rule works OK if I write mywebsite.com/something. In this case it's correctly redirected to www.mywebsite.com/something

However It seems as if the proxy has preference over what is written in the rewrite rules. That is to say, when it finds mywebsite.com/mywebsite, instead of rewriting it to www.mywebsite.com/mywebsite and then invoke Tomcat, it calls it inmediately without touching the URL.

Do you know any way to force the rewriting of the URL before proxying to Tomcat?

codependent
  • 23,193
  • 31
  • 166
  • 308

1 Answers1

0

Try this as your first line:

RewriteCond %{HTTP_HOST} ^mywebsite.com$ [NC]
Jordan Denison
  • 2,649
  • 14
  • 14