: Redirect https://example.com naked to https://www.example.com I am redirecting all http:// request to https:// using apache2 virtual host file: <VirtualHost *:80> ServerName example.com
I am redirecting all request to using apache2 virtual host file:
<VirtualHost *:80>
ServerName example.com
ServerAlias example.com Redirect / www.example.com/ </VirtualHost>
<VirtualHost *:443>
ServerName example.com #more details here
</VirtualHost>
This is working fine and redirecting all request to , but now I want to redirect my non-www request to I tried to add these lines before and after the above <VirtualHost *:443> with no success.
<VirtualHost *:443>
ServerName example.com
Redirect / www.example.com/ </VirtualHost>
How can I make it redirect from non-www to www whilst enforcing SSL in the virtual host file?
More posts by @Karen161
1 Comments
Sorted by latest first Latest Oldest Best
Try something like this:
<VirtualHost *:80>
ServerName example.com
ServerAlias example.com DocumentRoot "/path/to/port/80/site"
</VirtualHost>
<VirtualHost *:443>
ServerName example.com
ServerAlias example.com DocumentRoot "/path/to/port/443/site"
</VirtualHost>
Create an .htaccess file in /path/to/port/80/site with:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ www.example.com/ [R=301,L]
Create an .htaccess file in /path/to/port/443/site with:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule ^(.*)$ www.example.com/ [R=301,L]
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.