У меня есть VPS в Цифровом океане, на котором размещены два веб-сайта, каждый с несколькими доменами.
Веб-сайт 1: https://jeremiahrose.com/
Альтернативные домены:
jeremiahro.se
,
jeremiahrose.band
,
www.jeremiahrose.com
,
www.jeremiahro.se
,
www.jeremiahrose.band
Веб-сайт 2: https://thewilliewagtails.band/
Альтернативные домены:
thewilliewagtails.com
,
thewilliewagtails.com.au
,
www.thewilliewagtails.band
,
www.thewilliewagtails.com
,
www.thewilliewagtails.com.au
,
I'm trying to set it up so that a request to any of the alternative domains (http or https) redirects to the secure canonical domain for that website. e.g www.thewilliewagtails.com
redirects to https://thewilliewagtails.band
.
It's currently only half working - www.thewilliewagtails.com and thewilliewagtails.com are returning a default page, and thewilliewagtails.band/ is not redirecting.
I can't for the life of me figure out what the problem is, I'm clearly out of my depth here.
jez@jeremiahrose:/etc/apache2$ ls sites-enabled/
000-default.conf jeremiahrose.com.conf thewilliewagtails.band.conf
<VirtualHost *:80>
ServerAdmin example@gmail.com
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerAdmin example@gmail.com
DocumentRoot /var/www/jeremiahrose.com
<Directory /var/www/jeremiahrose.com/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<IfModule mod_dir.c>
DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm
</IfModule>
ServerName jeremiahrose.com
ServerAlias jeremiahro.se
ServerAlias jeremiahrose.band
ServerAlias www.jeremiahrose.com
ServerAlias www.jeremiahro.se
ServerAlias www.jeremiahrose.band
RewriteEngine on
#Added automatically by let's encrypt:
RewriteCond %{SERVER_NAME} =www.jeremiahrose.com [OR]
RewriteCond %{SERVER_NAME} =jeremiahrose.band [OR]
RewriteCond %{SERVER_NAME} =www.jeremiahro.se [OR]
RewriteCond %{SERVER_NAME} =jeremiahro.se [OR]
RewriteCond %{SERVER_NAME} =jeremiahrose.com [OR]
RewriteCond %{SERVER_NAME} =www.jeremiahrose.band
RewriteRule ^ https://jeremiahrose.com%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin example@gmail.com
DocumentRoot /var/www/jeremiahrose.com
<Directory /var/www/jeremiahrose.com/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<IfModule mod_dir.c>
DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm
</IfModule>
ServerName jeremiahrose.com
ServerAlias jeremiahro.se
ServerAlias jeremiahrose.band
ServerAlias www.jeremiahrose.com
ServerAlias www.jeremiahro.se
ServerAlias www.jeremiahrose.band
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.jeremiahrose.com [OR]
RewriteCond %{SERVER_NAME} =jeremiahrose.band [OR]
RewriteCond %{SERVER_NAME} =www.jeremiahro.se [OR]
RewriteCond %{SERVER_NAME} =jeremiahro.se [OR]
RewriteCond %{SERVER_NAME} =www.jeremiahrose.band
RewriteRule ^ https://jeremiahrose.com%{REQUEST_URI} [END,NE,R=permanent]
Include /etc/letsencrypt/options-ssl-apache.conf
Include /etc/letsencrypt/options-ssl-apache.conf
Include /etc/letsencrypt/options-ssl-apache.conf
Include /etc/letsencrypt/options-ssl-apache.conf
Include /etc/letsencrypt/options-ssl-apache.conf
Include /etc/letsencrypt/options-ssl-apache.conf
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/jeremiahro.se/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/jeremiahro.se/privkey.pem
</VirtualHost>
</IfModule>
<VirtualHost *:80>
ServerAdmin example@gmail.com
DocumentRoot /var/www/thewilliewagtails.band
<Directory /var/www/thewilliewagtails.band/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<IfModule mod_dir.c>
DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm
</IfModule>
ServerName thewilliewagtails.band
ServerAlias thewilliewagtails.com.au
ServerAlias thewilliewagtails.com
ServerAlias wwww.thewilliewagtails.com
ServerAlias www.thewilliewagtails.com.au
ServerAlias www.thewilliewagtails.band
RewriteEngine on
#Added automatically by let's encrypt:
RewriteCond %{SERVER_NAME} =www.thewilliewagtails.com [OR]
RewriteCond %{SERVER_NAME} =thewilliewagtails.com [OR]
RewriteCond %{SERVER_NAME} =www.thewilliewagtails.band [OR]
RewriteCond %{SERVER_NAME} =thewilliewagtails.com.au [OR]
RewriteCond %{SERVER_NAME} =www.thewilliewagtails.com.au
RewriteRule ^ https://thewilliewagtails.band%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin example@gmail.com
DocumentRoot /var/www/thewilliewagtails.band
<Directory /var/www/thewilliewagtails.band/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<IfModule mod_dir.c>
DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm
</IfModule>
ServerName thewilliewagtails.band
ServerAlias thewilliewagtails.com
ServerAlias thewilliewagtails.com.au
ServerAlias www.thewilliewagtails.com
ServerAlias www.thewilliewagtails.com.au
ServerAlias www.thewilliewagtails.band
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.thewilliewagtails.com [OR]
RewriteCond %{SERVER_NAME} =thewilliewagtails.com [OR]
RewriteCond %{SERVER_NAME} =www.thewilliewagtails.com.au [OR]
RewriteCond %{SERVER_NAME} =thewilliewagtails.com.au [OR]
RewriteCond %{SERVER_NAME} =www.thewilliewagtails.band
RewriteRule ^ https://thewilliewagtails.band%{REQUEST_URI} [END,NE,R=permanent]
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/jeremiahro.se/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/jeremiahro.se/privkey.pem
</VirtualHost>
</IfModule>
Kungoku nje kusebenza isiqingatha -
www.thewilliewagtails.com
andthewilliewagtails.com
are ndibuyisela iphepha elingagqibekanga, kwayethewilliewagtails.band/
ayihambisi kwakhona.
Andiboni nje ukuba kutheni thewilliewagtails.com
ibingazukusebenza. Nangona kunjalo, unayo itypo yakho
container, ehambelana wwww
, hayi www
kwi ServerAlias
- ke oku ngekhe kuhambelane:
ServerAlias wwww.thewilliewagtails.com
Kwaye thewilliewagtails.band
ishiyiwe kwi-HTTP yakho ukuya kwi-HTTPS (
) phinda uthumele (ulahlekile RewriteCond
] isikhombisi) -ewe, ayizukuphinda iqondiswe kuseto lwangoku. Endaweni yokujonga lonke igama lenginginya elinokubakho akufuneki libe njalo, kufuneka ujonge ukuba yi hayi igama lomamkeli (jonga ngezantsi).
Ndivumelana ngokupheleleyo nempendulo ka- @ roaima. Nangona kunjalo, uyinxalenye yendlela apho uqwalaselo lwakho lwangoku kwaye izikhombisi zakho zingenziwa lula.
Kuba izibuko lakho eliphefumlelweyo lingama-443, udinga kuphela imo_alias eyithumela kwakhona
kwi
izikhongozeli (mod_rewrite ayimfuneko) ukwenza ngokufanelekileyo i-HTTP ukuya kwi-HTTPS kwakhona. Ke, umzekelo, le mod_rewrite block ilandelayo:
Phinda ubhale iEngine #Kongezelelwa ngokuzenzekelayo ngoku masifihle: Phinda ubhale kwakhonaCond% {SERVER_NAME} = www.thewilliewagtails.com [OKANYE] Phinda ubhale kwakhonaCond% {SERVER_NAME} = thewilliewagtails.com [OR] Phinda ubhale uCond% {SERVER_NAME} = www.thewilliewagtails.band [OKANYE] Phinda ubhale kwakhonaCond% {SERVER_NAME} = thewilliewagtails.com.au [OR] Phinda ubhale iCond% {SERVER_NAME} = www.thewilliewagtails.com.au Phinda ubhaleRule ^ https: //thewilliewagtails.band% {REQUEST_URI} [END, NE, R = esisigxina]
Ingatshintshwa kwangoko nge-mod_alias elula / engenamiqathango Phinda uqondise kwakhona
endaweni yoko:
Redirect 301 / https://thewilliewagtails.band/
Kwaye i-mod_rewrite ehambelana nokuhanjiswa kwakhona kwi-1132637]
Phinda ubhale kwakhona iEngine Phinda ubhale kwakhonaCond% {SERVER_NAME} = www.thewilliewagtails.com [OKANYE] Phinda ubhale kwakhonaCond% {SERVER_NAME} = thewilliewagtails.com [OR] Phinda ubhale uCond% {SERVER_NAME} = www.thewilliewagtails.com.au [OKANYE] Phinda ubhale kwakhonaCond% {SERVER_NAME} = thewilliewagtails.com.au [OR] Phinda ubhale iCond% {SERVER_NAME} = www.thewilliewagtails.band Phinda ubhaleRule ^ https: //thewilliewagtails.band% {REQUEST_URI} [END, NE, R = esisigxina]
Inokutshintsha endaweni yayo ngokulula:
RewriteCond %{HTTP_HOST} !^thewilliewagtails\.band$
RewriteRule ^ https://thewilliewagtails.band%{REQUEST_URI} [R=permanent,L]
Kuninzi okunokukhunjulwa / ukuphosakela.
Nangona kunjalo, kusenokwenzeka ukuba ndiyaqhubeka nokwenza isikhongozeli esahlukileyo seVHost kwizibuko elingelilo elingu-443 amagama abamba iindwendwe njengoko kucetyiswa ngu @roaima. Ungasebenzisa imod_alias engenamiqathango Phinda uthumele
kwaye ulahle mod_rewrite ngokupheleleyo.
Isisombululo esilula ngaphandle kokungena ekubuyiseni ngokutsha imigaqo-nkqubo.
Kwiwebhusayithi nganye kunye nezivumelwano zayo:
Redirect
ukuthumela abasebenzisi kwi-canonical vHost.