1

I would like to redirect www and non-www with a subdomain to non-www HTTPS.

I think this should clarify.

<VirtualHost *:80>
    DocumentRoot "C:/www/eshop"
    ServerName shop.example.com
    ServerAlias www.shop.example.com
# shop.example.com should redirect to https://shop.example.com
# www.shop.example.com should redirect to https://shop.example.com

</VirtualHost>

<VirtualHost *:443> DocumentRoot "C:/www/eshop" ServerName shop.example.com ServerAlias www.shop.example.com

# I would like to redirect www and non-www to https://shop.example.com

# https://shop.example.com should redirect to https://shop.example.com
# https://www.shop.example.com should redirect to https://shop.example.com

&lt;Directory &quot;C:/www/eshop&quot;&gt;
    # some code will go here
&lt;/Directory&gt;

</VirtualHost>

Roland
  • 113

1 Answers1

0

Use the Redirect directive for simple redirects:

<VirtualHost *:80>
    ServerName shop.example.com
    ServerAlias www.shop.example.com
    Redirect "/" "https://shop.example.com/"
</VirtualHost>

<VirtualHost *:443> ServerName www.shop.example.com Redirect "/" "https://shop.example.com/" # ... Maybe some SSL configuration is needed here </VirtualHost>

<VirtualHost *:443> DocumentRoot "C:/www/eshop" ServerName shop.example.com # ... Maybe some SSL configuration is needed here

&lt;Directory &quot;C:/www/eshop&quot;&gt;
    # some code will go here
&lt;/Directory&gt;

</VirtualHost>

HBruijn
  • 84,206
  • 24
  • 145
  • 224