Incredible Apache2 virtualhost redirection issue… solved.

Last week I've been stuck with an incredible issue testing websites locally.

Never had a problem since then; I usually set up my hosts file and create a virtualhost in order to test mywebsitename.test in my browser, then when I'm done I move it on production and change config files.

Nothing simplier.

But for some reason the process suddenly broke and I got this strange behavior:

when I opened my browser and went to site1.test (i.e.), my browser redirected me to site2.test.

Ok, so I searched for some strange config errors in my .htaccess, but it was absolutely well formed.

Then I dig through Webmin services (yes, I use Webmin to manage my local workstation and I absolutely love it), found nothing.

My /etc/hosts file was something like:

127.0.0.1 site1.test www.site1.test
127.0.0.1 site2.test www.site2.test

and my virtualhost setup was good, at a glance:

in /etc/apache2/sites-available I had my .conf files and my symlinks in /etc/apache2/sites-enabled for every website:

<VirtualHost *:80>
ServerName mywebsite.test
ServerAlias *.mywebsite.test

DocumentRoot /var/www/html/myfolder/mywebsite

<Directory /var/www/html/myfolder/mywebsite>
Require all granted

AllowOverride all
</Directory>

RewriteEngine on
RewriteOptions inherit

# cut boring things for the sake of readibility
 
</VirtualHost>

but I continued to be redirected from site1.test to site2.test

... At that point, I was stuck. What else could I've done?

... ok, at this point a good read would be

"... then I found the solution! The problem was in xyz.naah file, in /incredibly/deep/folder/in/my/os/ and then I rot13'd my first pet's name, reversed it and used as salt for my password in my Ethereum wallet, then bought with my cryptocoins a pyramid and buried in it a scroll with the GPL license on it and they lived happily ever after"

but the cold reality is that I really dunno how I fixed it.

All that I can do is to list what I've done to restore the status.

First, I stopped Webmin.
Second I deleted all my /sites-enabled and /sites-available configs (after a backup).
Third, I deleted every commented file in my .hosts file (absolutely useless but oh, well).
Then I restored every website virtualhost, one .conf at a time.
So I a2ensite'd every single website, restarted Apache and also restarted networking service with sudo service network-manager restart
Lastly, I deleted all my Chrome and Firefox cache and visited every site at first using www.mysitename.test (not letting my browser solve the third level of the domain: another useless thing but oh, well again).
I tried also to update my system but no updates were available at the time.

I'm absolutely conscious that none of these things could technically have solved my issue, but I had no more shots in my locker so I tried the only thing could make things go well and solve problems:

METHOD

Probably I've made some mistake in writing something somewhere. Mystic colon, who knows. 
Or maybe an update fixed it before I did all my diligent work, dunno.

The only thing I know is that now I can develop again my sites and web apps locally and the issue is solved.

HIH

Leave a Reply

Your email address will not be published. Required fields are marked *

9 − eight =