0

I just switched to a new server running 2.4.7 from 2.2.x and now i'm having a few issues. I resolved most of them that I ran across so far except this permanent redirect issue. Here is the code:

<VirtualHost *:80>
    ServerName example.com
    ErrorLog /var/log/apache2/example.com.error.log
    CustomLog /var/log/apache2/example.com.custom.log common
    Redirect 301 / http://www.example.com/
#    RedirectMatch permanent /(.*) http://www.example.com/$1
</VirtualHost>

<VirtualHost *:80>
        ServerAdmin 393@7079.net
        ServerName www.example.com
#       ServerAlias example.com
        DocumentRoot /home/www/example
        ErrorLog /var/log/apache2/www.example.com.error.log
        CustomLog /var/log/apache2/www.example.com.custom.log common
        DirectoryIndex index.jsp index.html
        <IfModule jk_module>
                JkMount /*.cfm worker1
                JkMount /*.cfc worker1
                JkMount /*.do worker1
                JkMount /*.jsp worker1
                JkMount /*.cfchart worker1
                JkMount /*.cfm/* worker1
                JkMount /*.cfml/* worker1
                #JkMount /railo-context/* worker1
                JkLogFile /var/log/apache2/mod_jk.log
        </IfModule>

        <Directory /home/www/example/>
                Require all granted
        </Directory>
</VirtualHost>

When I visit http://example.com, it's showing the default apache page for the /var/www/html site rather than performing the redirect. I have 2 servers running 2.4.7 and they both behave the same way, the old servers were running this code fine. I tried to use RedirectMatch which you is commented out since that did not work either. I also commented out the first vhost that was redirecting to the www vhost and added an alias to it just to get it working until i make time for it in the future to figure it out, but the ServerAlias did not render the site, it rendered the default html/index.html page.

I am puzzled and don't know where to begin. Countless hours of Googling and search the forum and there is not a single solution that I ran across. Maybe someone else has experienced this and solved, if so please let me know what the solution is.

BTW, I am looking for a non "rewrite" solution, i prefer the permanent redirect instead.

Hatem Jaber
  • 2,341
  • 2
  • 22
  • 38

2 Answers2

0

The temporary work around was to remove the default apache vhost. This is a temporary fix and will be an issue once another vhost is added to apache since one of the vhosts will have to be the "default".

Hatem Jaber
  • 2,341
  • 2
  • 22
  • 38
0

I've been playing around for many days with Apache 2.4.7 on an Ubuntu 14.04LTS fresh install and I had similar problems than you regarding redirections...

It seems that on Apache 2.4.7 the order where the code is called affects the result. And the rule that worked for me is that the redirect directive should be always after the main site VirtualHost.

What I made to solve this on each site is the following:

  1. I created an extra folder called sites-redirection

sudo mkdir /etc/apache2/sites-redirection

  1. On apache2.conf I added a rule to load all redirection files AFTER sites-available loads like this:
IncludeOptional sites-enabled/*.conf

IncludeOptional sites-redirection/*.conf
  1. I add a file per site with the redirection code. Here is an example:
<VirtualHost *:80>
  ServerName origin.website.com
  RewriteEngine on
  Redirect 301 / http://destination.website.com
</VirtualHost>

For the Rewrite directive to work you should install mod_rewrite and restart apache2 server.

sudo a2enable rewrite sudo service apache2 restart