so far i have this (nothing happens)
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www. RewriteCond %{HTTPS}s on(s)|offs() RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]
ServerAdmin admin@mydomain.com
ServerName mydomain.com
ServerAlias www.mydomain.com
DocumentRoot /var/www/mydomain.com
i read and tried everything i saw in the net but of no avail.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
It’s easier this way…
<VirtualHost *:80>
ServerName example.com
Redirect permanent / https://example.com/
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
</VirtualHost>
<VirtualHost *:80>
ServerName www.example.com
Redirect permanent / https://example.com/
</VirtualHost>
thanks rushpro…im going to try this…xx . . . error…when i restart the apache2 i got failed & when i checked the error log (fatal error and some sort of error things i can’t relate) . . . anyway i got it worked…it is so simple…it goes like this:
you make vhost settings:
<VirtualHost *:80>
ServerName example.com
Redirect permanent / https://example.com/
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
</VirtualHost>
and then, you go Let’s Encrypt https://www.digitalocean.com/community/tutorials/how-to-secure-apache-with-let-s-encrypt-on-ubuntu-14-04
after that, you recheck you’re mydomain.com.conf (where you put you’re vhost settings) in the lower part you will get settings like this before the end of </VirtualHost>:
RewriteEngine on RewriteCond %{SERVER_NAME} =www.mydomain.com [OR] RewriteCond %{SERVER_NAME} =mydomain.com RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
i change mydomain.com to www.mydomain.com…
RewriteEngine on RewriteCond %{SERVER_NAME} =www.mydomain.com [OR] RewriteCond %{SERVER_NAME} =www.mydomain.com RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
i checked chrome and firefox so far it works for me…anyway thanks for your comment it gives me an idea.
To redirect non-www to www for your domain using Apache, you need to correctly configure either the .htaccess file or the Apache virtual host configuration. Here’s a step-by-step guide for both approaches.
.htaccess for RedirectIf you’re using .htaccess, try the following configuration:
.htaccess File in your document root (/var/www/mydomain.com):sudo nano /var/www/mydomain.com/.htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
This will redirect any non-www requests to the www version, regardless of whether the request is over HTTP or HTTPS.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.