简体   繁体   中英

apache redirect loop in virtual host

I have the entry below in my .conf file that I set up for Jenkins.

 <VirtualHost *:80>
            ServerName my.server.com
            Redirect 301 / http://my.server.com/factory
            ProxyPass /factory http://localhost:8080/factory nocanon
            ProxyPassReverse /factory localhost:8080/factory
            ProxyRequests Off
            AllowEncodedSlashes NoDecode
            <Proxy http://localhost:8080/factory*>
                    Order deny,allow
                    Allow from all
            </Proxy>
    </VirtualHost>

I redirect fine from my.server.com as expected. But, if I put a URL that doesn't exist such as my.server.com/test it sends me into a redirect loop. I am ok with non existent URLs like /test showing 404 pages, I just want my home page to redirect to /factory.

My Apache knowledge is currently about 0, so if you can explain like I'm 5 that would be great. I'm just trying to get this up and running and plan on continually learning as I go.

First load mod_rewrite in your Apache and try updated config below.

<VirtualHost *:80>
    ServerName my.server.com

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^my\.server\.com$ [NC] # if host is my.server.com
    RewriteCond %{REQUEST_URI} !(^/factory$) [NC]   # and request uri is NOT factory
    RewriteRule ^(.*)$ http://my.server.com/factory [R=301,L] # redirect to url

    ProxyPass /factory http://localhost:8080/factory nocanon
    ProxyPassReverse /factory localhost:8080/factory
    ProxyRequests Off
    AllowEncodedSlashes NoDecode
         <Proxy http://localhost:8080/factory*>
           Order deny,allow
           Allow from all
         </Proxy>
</VirtualHost>

Hope that helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM