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
  • 11,643
  • 4
  • 25
  • 40
  • Have you tried this? https://www.devside.net/wamp-server/how-to-redirect-root-url-to-another-sub-directory-or-url – dave Jun 26 '18 at 09:39
  • it is still redirecting to http://example.com/jenkinsjenkinsjenkinsjenkinsjenkinsjenkinsjenkinsjenkinsjenkinsjenkinsjenkinsjenkinsjenkinsjenkinsjenkinsjenkinsjenkins – user2916639 Jun 26 '18 at 09:46
  • I checked it - I installed apache 2.4.7 and added to /etc/apache2/apache2.conf only: RedirectMatch ^/$ http://127.0.0.1/jenkins - and after apache restart it works for me properly. Can you comment all your changes and do exactly what I did? – dave Jun 26 '18 at 09:56
  • So i should make this entry in apache conf file or vhost – user2916639 Jun 26 '18 at 09:57
  • Please add this in conf file. – dave Jun 26 '18 at 09:59
  • Now it is redirecting to wrong URL even reverting all changes – user2916639 Jun 26 '18 at 10:08

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
  • 11,643
  • 4
  • 25
  • 40
  • should i make this change httpd.conf or jenkins.conf – user2916639 Jun 26 '18 at 10:10
  • The same place you had the original `Redirect` - in your `` container by the looks (so yes, in `example.conf`). – MrWhite Jun 26 '18 at 10:12
  • i am using httpd 2.4 with centos. Now i have reverted all the changes but URL is still redirecting. Is there any cache thing in httpd – user2916639 Jun 26 '18 at 10:50
  • Are you saying it's still redirecting to `example.com/jenkinsjenkins...`? If that is the case then either the erroneous code is still present or you are seeing a cached response. Unless you have an additional proxy cache on your network then the only cache is your browser. If you've previously experimented with 301 (permanent) redirects then these are likely to be cached persistently by your browser. Check the network traffic (in the browser), what do you see? What status code (3xx) are you seeing? – MrWhite Jun 26 '18 at 10:58
  • i used 301 permanent redirect before. since it is not getting revert. Now it is behaving same on all user end machines. Config level changed I reverted already. in browser it is showing 301 get . – user2916639 Jun 26 '18 at 11:22
  • In that case, you are seeing a cached response - you need to clear your browser cache (and any intermediary caches you might have). – MrWhite Jun 26 '18 at 11:27