Page 1 of 1
weird problem,,redirecting to www and https
Posted: Thu Dec 31, 2015 3:50 am
by lokali
i'm redirecting non www to www using htaccess
Code: Select all
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
it only redirects on homepage only.. when i type mydomain.com/suboage.html is not redirected to www.. how to redirect all subpage?
and the second redirecting to https using code
Code: Select all
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
it only redircts on homepage only too..when i type mydomain.com/suboage.html is not redirected to https.. how to redirect all subpage?
Re: weird problem,,redirecting to www and https
Posted: Thu Dec 31, 2015 7:16 am
by mike08
Hey lokali,
For the www redirect I have the following in .htaccess:
Code: Select all
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
And for https I have on: /home/admin/conf/web/nginx.conf the following:
Code: Select all
return 301 https://$server_name$request_uri;
So the settings for the nginx.conf virtual host look like this:
Code: Select all
server {
listen 192.168.1.150:80;
server_name localehost.com www.localehost.com;
error_log /var/log/apache2/domains/localehost.error.log error;
return 301 https://$server_name$request_uri;
...
EDIT: Make sure to restart nginx after applying the config
Hope that helps.
Re: weird problem,,redirecting to www and https
Posted: Thu Dec 31, 2015 8:55 am
by tjebbeke
I have this htaccess:
Code: Select all
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !localhost
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [L,R=301]
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
</IfModule>
Re: weird problem,,redirecting to www and https
Posted: Thu Dec 31, 2015 10:52 pm
by lokali
please help me ..all don't work
actually the rediredtion works on domain.com/ but not work on domain.com/index.html and work for domain.com/page/ but not work on domain.com/page.html
so all my html page not redirected
i dont know what rule i should insert :(
i have tried all rule on google and not work for static .html :(
Re: weird problem,,redirecting to www and https
Posted: Fri Jan 01, 2016 2:36 am
by lokali
i can confirm that this is BUG of vestaCP
i have the following htaccess code, my htaccess redirect non www to www and http to https that WORK redirection .html on MY CPANEL HOSTING but not work on vestacp..i have installed fresh vestacp and get the same problem. so this is vestacp problem
Vestacp htacess redirection:
actually the rediredtion works on domain.com/ but not work on domain.com/index.html and work for domain.com/page/ but not work on domain.com/page.html
on cpanel hosting:
the same htaccess code work to redirect http to https and non www to www on all pages .html
i have tried htaccess on vestacp doc and it also not work to redirect .html
if you have htacess redirection,,just double check if it work on static .html page or not
so this is bug of vesta cp, because of this problem i'm considering to find another control panel
Code: Select all
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
Re: weird problem,,redirecting to www and https
Posted: Sun Apr 05, 2020 4:29 pm
by scetticus
If your problem is redirecting both yourdomain.com and
www.yourdomain.com to
https://www.yourdomain.com you have to follow the official guide at
https://vestacp.com/docs/#how-to-force-https
BUT THEN EDIT
/usr/local/vesta/data/templates/web/nginx/force-https.tpl
replacing all content with this:
Code: Select all
server {
listen %ip%:%proxy_port%;
server_name %domain_idn% %alias_idn%;
location / {
rewrite ^(.*) https://%alias_idn%$1 permanent;
}
include %home%/%user%/conf/web/*nginx.%alias_idn%.conf_letsencrypt;
}
You'll se that I changed only %domain_idn% with %alias_idn% in rewrite and include rules...
Remember to deselect, save, reselect and save again "force-https" as proxy template if you already installed and used it before... then restart both nginx and https.
Glad if this helps.