Redirect does not work for 1 virtual host


#1

Hi,

My problem is as follows. I am currently running three virtual hosts, all of which have an SSL certificate. Two out of three virtual hosts are redirecting from HTTP to HTTPS without any issues - e.g. if I type in http://zizek.uk it redirects to https://zizek.uk without any issues. However, for some reason one of the domains does not redirect: http://paradoxoftheday.com directs to main root (i.e. /var/www/html) instead of to its assigned directory (i.e. /var/www/html/paradoxoftheday). [EDIT: this is if you use other browser than Chrome, which automatically prefers HTTPS, e.g. Opera.] All configuration files (in /etc/apache2/sites-available) are set up identically. All .htaccess files are set up identically. And yet, for some reason, zizek.uk does redirect to HTTPS while paradoxoftheday.com does not redirect to HTTPS and instead directs to root directory (which as mentioned is one level higher). Both websites are Wordpress, if that is important.

My domain is: paradoxoftheday.com and zizek.uk

I ran this command: N/A

It produced this output: N/A

My web server is (include version): I don’t know

The operating system my web server runs on is (include version): Debian 8 x64, version 9.4

My hosting provider, if applicable, is: NFPhosting

I can login to a root shell on my machine (yes or no, or I don’t know): yes

I’m using a control panel to manage my site (no, or provide the name and version of the control panel): no


#2

Which method are you using to redirect?
Is it the same method for all 3 sites?


#3

What do you mean by method? Redirect was arranged by certbot (one of the questions): it added a few lines to the apache config file. All lines looks the same.


#4

Hi @ippolit

then you may have a redirect on another place. Please share your complete Apache configuration file.

http://paradoxoftheday.com/ shows the default apache page, https://paradoxoftheday.com/ shows content.


#5
<IfModule mod_ssl.c>
<VirtualHost *:443>
	ServerName paradoxoftheday.com
	ServerAlias www.paradoxoftheday.com

	DocumentRoot /var/www/html/potd

	<Directory />
		Options FollowSymLinks
		AllowOverride None
	</Directory>
	<Directory /var/www/html/potd>
		Options Indexes FollowSymLinks MultiViews
		AllowOverride All
		Order allow,deny
		allow from all
	</Directory>

	ErrorLog /var/www/html/potd/error.log

	# Possible values include: debug, info, notice, warn, error, crit,
	# alert, emerg.
	LogLevel warn

	CustomLog /var/www/html/potd/access.log combined

SSLCertificateFile /etc/letsencrypt/live/paradoxoftheday.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/paradoxoftheday.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>

As mentioned previously, this is identical to zizek.uk configuration file, except for domain names and directories being changed.

The default apache pages is in this directory ‘/var/www/html/’, so I have no idea why it directs there.

EDIT: in case you need the *:80 instead

<VirtualHost *:80>
	ServerName paradoxoftheday.com
	ServerAlias www.paradoxoftheday.com
	
	DocumentRoot /var/www/html/potd

	<Directory />
		Options FollowSymLinks
		AllowOverride None
	</Directory>
	<Directory /var/www/html/potd>
		Options Indexes FollowSymLinks MultiViews
		AllowOverride All
		Order allow,deny
		allow from all
	</Directory>

	ErrorLog /var/www/html/potd/error.log

	# Possible values include: debug, info, notice, warn, error, crit,
	# alert, emerg.
	LogLevel warn

	CustomLog /var/www/html/potd/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =paradoxoftheday.com [OR]
RewriteCond %{SERVER_NAME} =www.paradoxoftheday.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

#6

That *:80 conf looks correct.
There must be another conf that conflicts…

Please show:
grep -Eri 'ServerName|ServerAlias' /etc/apache2


#7

Thanks for your response. This is what I get:

|/etc/apache2/sites-available/zizek-le-ssl.conf:|ServerName zizek.uk|
|---|---| <---- This line is not there in the output, not sure why it is showing up here.
|/etc/apache2/sites-available/zizek-le-ssl.conf:|ServerAlias www.zizek.uk|
|/etc/apache2/sites-available/philfaqs-le-ssl.conf:|ServerName philosophyfaqs.com|
|/etc/apache2/sites-available/philfaqs-le-ssl.conf:|ServerAlias www.philosophyfaqs.com|
|/etc/apache2/sites-available/nietzsche.conf:|ServerName aphil.org|
|/etc/apache2/sites-available/nietzsche.conf:|ServerAlias www.aphil.org|
|/etc/apache2/sites-available/potd-le-ssl.conf:|ServerName paradoxoftheday.com|
|/etc/apache2/sites-available/potd-le-ssl.conf:|ServerAlias www.paradoxoftheday.com|
|/etc/apache2/sites-available/zizek.conf:|ServerName zizek.uk|
|/etc/apache2/sites-available/zizek.conf:|ServerAlias www.zizek.uk|
|/etc/apache2/sites-available/quotes.conf:|ServerName paradoxquotes.com|
|/etc/apache2/sites-available/quotes.conf:|ServerAlias www.paradoxquotes.com|
|/etc/apache2/sites-available/classics.conf:|ServerName classics.paradoxoftheday.com|
|/etc/apache2/sites-available/philfaqs.conf:|ServerName philosophyfaqs.com|
|/etc/apache2/sites-available/philfaqs.conf:|ServerAlias www.philosophyfaqs.com|
|/etc/apache2/sites-available/potd.conf:|ServerName paradoxoftheday.com|
|/etc/apache2/sites-available/potd.conf:|ServerAlias www.paradoxoftheday.com|
|/etc/apache2/sites-available/000-default.conf:|# The ServerName directive sets the request scheme, hostname and port that|
|/etc/apache2/sites-available/000-default.conf:|# redirection URLs. In the context of virtual hosts, the ServerName|
|/etc/apache2/sites-available/000-default.conf:|#ServerName www.example.com|
|/etc/apache2/mods-available/info.conf:|#  http://servername/server-info (requires that mod_info.c be loaded).|
|/etc/apache2/mods-available/status.conf:|# with the URL of http://servername/server-status|

#8

It seems you have three files that use that same domain:
|/etc/apache2/sites-available/potd-le-ssl.conf:|ServerName paradoxoftheday.com| |/etc/apache2/sites-available/quotes.conf:|ServerName paradoxquotes.com| |/etc/apache2/sites-available/potd.conf:|ServerName paradoxoftheday.com|

Now, one is for SSL and one is for HTTP.
That means there is an extra file for HTTP that is unaccounted for and is likely creating the problem.


#9

quotes.conf was a test configuration that is no longer used. I have removed the conf file and restarted apache. I still have the same issue though.


#10

Thanks to your answer, I did find the culprit. For some reason the ‘default’ configuration was still enabled (I guess I did that early on), and that was the conflicting configuration that redirected me to the root directory. Problem solved!


#11

Thanks. Good to know :wink:


#12

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.