Answer the question
In order to leave comments, you need to log in
Why doesn't redirect from https://www to non-www https:// work?
Good day to all!
Guys, for some reason, the https redirect does not work for me on non-WWW links with subdirectories. The main domain https://www.site.com redirects to https://site.com, but for example from https://www.site.com/question/new to https:/site.com/question/new no. Yes, they are indexed by search engines. With http redirect works and goes to https.
server {
listen 00.00.00.00:80;
server_name site.com www.site.com;
return 301 https://site.com$request_uri;
}
server {
listen 00.00.00.00:80;
server_name site.com;
error_log /var/log/apache2/domains/site.com.error.log error;
location / {
proxy_pass http://00.00.00.00:8080;
location ~* ^.+\.(jpg|jpeg|gif|png|ico|svg|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|odt|ods|odp|odf|tar|wav|bmp|rtf|js|mp3|avi|mpeg|flv|html|htm)$ {
root /home/admin/web/site.com/public_html;
access_log /var/log/apache2/domains/site.com.log combined;
access_log /var/log/apache2/domains/site.com.bytes bytes;
expires max;
try_files $uri @fallback;
}
}
location /error/ {
alias /home/admin/web/site.com/document_errors/;
}
location @fallback {
proxy_pass http://00.00.00.00:8080;
}
location ~ /\.ht {return 404;}
location ~ /\.svn/ {return 404;}
location ~ /\.git/ {return 404;}
location ~ /\.hg/ {return 404;}
location ~ /\.bzr/ {return 404;}
include /home/admin/conf/web/nginx.site.com.conf*;
}
server {
listen 00.00.00.00:443;
server_name site.com www.site.com;
ssl on;
ssl_certificate /home/admin/conf/web/ssl.site.com.pem;
ssl_certificate_key /home/admin/conf/web/ssl.site.com.key;
error_log /var/log/apache2/domains/site.com.error.log error;
location / {
proxy_pass https://00.00.00.00:8443;
location ~* ^.+\.(jpg|jpeg|gif|png|ico|svg|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|odt|ods|odp|odf|tar|wav|bmp|rtf|js|mp3|avi|mpeg|flv|html|htm)$ {
root /home/admin/web/site.com/public_html;
access_log /var/log/apache2/domains/site.com.log combined;
access_log /var/log/apache2/domains/site.com.bytes bytes;
expires max;
try_files $uri @fallback;
}
}
location /error/ {
alias /home/admin/web/site.com/document_errors/;
}
location @fallback {
proxy_pass https://00.00.00.00:8443;
}
location ~ /\.ht {return 404;}
location ~ /\.svn/ {return 404;}
location ~ /\.git/ {return 404;}
location ~ /\.hg/ {return 404;}
location ~ /\.bzr/ {return 404;}
include /home/admin/conf/web/snginx.site.com.conf*;
}
Answer the question
In order to leave comments, you need to log in
I solved my problem with the following code..
server {
listen 00.00.00.00:80;
server_name site.com www.site.com;
if ($host ~* ^(site\.com|www\.site\.com)$ ){
rewrite ^/(.*)$ https://site.com/$1 permanent;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question