I am trying to redirect to access the site with url: www.example.com but it is giving me 403 forbidden. site works with example.com , https://www.example.com https://example.com

here is my virtual host:

<VirtualHost :*80>
    ServerName www.example.com
    ServerAlias example.com
    DocumentRoot /home/asd/sites/example.com/public_html

  <Directory /home/asd/sites/example.com/public_html>
    AllowOverride all
    Options Indexes FollowSymLinks Includes ExecCGI
   Require all granted

 <VirtualHost *:443>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    ServerName  example.com
    ServerAlias www.example.com

    ServerAdmin  [email protected]
    DocumentRoot /home/asd/sites/example.com/public_html

    SSLEngine On
    SSLCertificateFile /home/asd/ssl_certs/example.com.crt
    SSLCertificateKeyFile /home/asd/ssl_certs/example.com.key
    SSLCACertificateFile /home/asd/ssl_certs/example.com.intermediate.crt

<Directory /home/asd/sites/example.com/public_html>
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^(www\.)(.*) [NC]
    RewriteRule (.*) https://%2%{REQUEST_URI} [L,R=301]

    AllowOverride all
    Options Indexes FollowSymLinks Includes ExecCGI
   Require all granted

I have tried enabling and disabling 000-default.conf as well. but if I enable that then the www.example goes to apache root index.html

https://www.example.com works fine though.

I have been trying to make it work for hours but I am unable to do so.Any help will be apprreciated.

I want all traffic go from non http to https and www to non www.


  • Presumably you've got both example.com and www.example.com in your hosts file. What do the logs say for the problematic requests?
    – BigRedS
    Sep 11, 2018 at 19:31

1 Answer 1


Turned out that it was a typo. Spent my whole day figuring out the issue.

It was:

 <VirtualHost :*80>

which should be:

 <VirtualHost *:80>
  • I did not notice this change for long. Happened to me exact same thing. I did not notice this issue at all for long :) Sep 12, 2018 at 14:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .