• Hi,

    Can someone please provide me htaccess code for the following purpose.

    1. Redirect non www requests to www version
    2. http requests to https

    I have already installed wild card ssl certificate on my domain.

    Thank in advance.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Add the following to your htaccess file! Remember to edit it for your domain name.

    # Force url with WWW
    RewriteBase /
    RewriteCond %{HTTP_HOST} !^site.com$ [NC]
    RewriteRule ^(.*)$ https://www.site.com/$1 [L,R=301]
    
    # Force https
    RewriteCond %{HTTP_HOST} ^site\.com [NC]
    RewriteCond %{SERVER_PORT} 80
    RewriteRule ^(.*)$ https://www.site.com/$1 [R,L]

    Hope this helps! Let us know if you have any problems!

    Thread Starter Jithin Johny Geogre

    (@jithin-johny-geogre)

    Thank for the reply. When I applied the code on my htaccess file, and reloaded my home page, I am getting the following error code.

    The https://www.site.com page isn’t working

    https://www.site.com redirected you too many times.
    Try:
    Reloading the page
    Clearing your cookies
    ERR_TOO_MANY_REDIRECTS

    Please read my message again. it is not as simple as just copying that code. Your url is not site.com. you need to change all instances of site.com to have your url.

    For instance, my url is dehnavi.net so my code would look like this

    # Force url with WWW
    RewriteBase /
    RewriteCond %{HTTP_HOST} !^dehnavi.net$ [NC]
    RewriteRule ^(.*)$ https://www.dehnavi.net/$1 [L,R=301]
    
    # Force https
    RewriteCond %{HTTP_HOST} ^dehnavi\.net [NC]
    RewriteCond %{SERVER_PORT} 80
    RewriteRule ^(.*)$ https://www.dehnavi.net/$1 [R,L]

    Please note: I do not have a site up at that address but that is the code I would use if I wanted to do what you are trying to do.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Htaccess help required’ is closed to new replies.