1

I have a vhost name example.conf that contains below lines.

<VirtualHost *:80>
ServerName example.com
ServerAdmin admin@myhost.com

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" combined
CustomLog /var/log/httpd/app1_access.log combined
ErrorLog /var/log/httpd/app1_error.log

redirect / http://example.com/jenkins
DirectoryIndex index.html index.php
JkMount /jenkins/* failover
JkMount /jenkins failover

</VirtualHost>

I want, if anyone hits http://example.com then it should open http://example.com/jenkins

My URL is redirecting to

http://example.com/jenkinsjenkinsjenkinsjenkinsjenkinsjenkinsjenkinsjenkinsjenkinsjenkinsjenkinsjenkinsjenkinsjenkinsjenkinsjenkinsjenkins

Like this.

It is Jenkins on tomcat with apache web server. Any help would be much appreciated.

MrWhite
  • 13,315

1 Answers1

1
redirect / http://example.com/jenkins

If redirecting to the same host then this will indeed result in a redirect loop because the Redirect directive uses simple prefix-matching and everything after the match is copied onto the end of the target URL. So, you will get the following:

  • / (Initial request)
  • /jenkins (first redirect)
  • /jenkinsjenkins (second redirect)
  • etc.

You need to use a RedirectMatch directive instead so you can match just the document root. RedirectMatch (also part of mod_alias) matches using a regex, instead of prefix-matching. For example:

RedirectMatch 302 ^/$ http://example.com/jenkins

I've included the optional status code argument to make it clear that this is a 302 (temporary) redirect (the default).

You'll need to restart Apache after making any changes to the server config. And, as always, make sure you've cleared your browser cache before testing.

MrWhite
  • 13,315