• [ Moderator note: moved to Fixing WordPress. Please do not use Developing With WordPress for these topics. ]

    I want to do the proper thing in my HTACCESS file… but when I follow some online tutorials – I get a message on my site saying there are too many redirects!

    My current HTACCESS says:

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    # END WordPress 

    > So what do I need to put in the code to tell search engines that the site is now changed, from HTTP to HTTPS ?

    All help appreciated!!!!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    in .htaccess, before the #BEGIN WordPress line

    RewriteEngine On 
    RewriteCond %{HTTP_HOST} ^example\.com [NC]
    RewriteCond %{SERVER_PORT} 80 
    RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
    Thread Starter gweb1

    (@gweb1)

    Thank you; reading on other forums; there seems to be confusion over the exact code to use… with the three examples below (including yours) – what would the differene be?

    1.

    RewriteEngine On 
    RewriteCond %{HTTP_HOST} ^EXAMPLE.COM [NC]
    RewriteCond %{SERVER_PORT} 80 
    RewriteRule ^(.*)$ https://WWW.EXAMPLE.COM/$1 [R,L]

    2.

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^EXAMPLE.COM [NC,OR]
    RewriteCond %{HTTP_HOST} ^WWW.EXAMPLE.COM [NC]
    RewriteRule ^(.*)$ https://WWW.EXAMPLE.COM/$1 [L,R=301,NC]

    3.

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^EXAMPLE.COM [OR]
    RewriteCond %{REQUEST_URI} !^/en
    RewriteRule ^(.*)$ https://WWW.EXAMPLE.COM/$1 [L,R=301,NC]
    Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    The one I recommended I know to work because I use it on my clients’ sites. ??

    Moderator bcworkz

    (@bcworkz)

    One difference is Steve’s is the only example that will not rewrite valid HTTPS requests. Why rewrite a valid request?

    I don’t know what !^/en is supposed to accomplish in #3. It has nothing to do with HTTP or port 80. It’s probably related to someone’s multi-language site.

    However, Steve’s example does not accommodate www. in the request. (Does anyone still type that anyway?) It’ll be in some links anyway. I would modify one line in Steve’s example, the rest are good.
    RewriteCond %{HTTP_HOST} ^(www\.)?example\.com [NC]

    The ? makes the preceding (group) optional.

    I noticed you dropped the backslashes in copying his example. You shouldn’t do that. Without the backslash, the dot could match anything. The backslash requires that only a dot match the dot. In a practical sense it would make little difference here. It’s a good practice when using regexp to do so. In other situations it can be a security risk to not do so.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘moved from http to https – what to put in htaccess file’ is closed to new replies.