0

example.com , now what I need is request comes to example.com and www.example.com redirect to https://www.example.com,

This is my apache redirect code

    RewriteEngine On
   RewriteCond %{HTTP_HOST} ^example.com$  [NC]
    RewriteRule ^(.*)$ https://www.example.com$1 [R=301,L]

If I add RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]

browser says too many redirects or redirect loop, how to solve this, I have sub domain configuration also so the condition not to affect subdomain redirects...

Navin
  • 103
  • 2

1 Answers1

1

You don't need mod_rewrite for this

<VirtualHost *:80>
    ServerName www.example.com
    ServerAlias example.com

    Redirect "/" "https://www.example.com/"
</VirtualHost >

But if you really want to use mod_rewrite

<VirtualHost *:80>
    ServerName www.example.com
    ServerAlias example.com

    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://www.example.com/%{REQUEST_URI} [R=301,L]
</VirtualHost >
user9517
  • 114,104
  • 20
  • 206
  • 289
  • see, the thing is i have some sub domain also , so I cant make Redirect "/" "https://www.example.com/" , I need www.example.com and exmaple.com to https://www.example.com – Navin Feb 04 '16 at 06:48
  • Just change the redirect targets and/or add the subdomain the ServerAlias. Or create a new vhost for the subdomain and redirect it appropriately. – user9517 Feb 04 '16 at 06:49
  • How to do that one? – Navin Feb 04 '16 at 06:52
  • 1
    A friendly search engine (even the one in the top right) and the documentation are your friend, I've stopped doing Reading Documentation As A Service. – user9517 Feb 04 '16 at 06:56