WordPress SSL htaccess code – Rewrite SSL, RewriteCond Server Port

Home Forums BulletProof Security Pro WordPress SSL htaccess code – Rewrite SSL, RewriteCond Server Port

Viewing 4 posts - 121 through 124 (of 124 total)
  • Author
    Posts
  • #42014
    verysingh
    Participant

    So since it is free and easy to get an SSL Certificate then that is the best route to go instead of trying to do some sort of 3rd party logo image hosting.

    #42424
    jose sally
    Participant

    Thanks, i’ll try it on my site

    #42426
    jose sally
    Participant

    I’ve successfully implemented it on my site applebees happy hour

    #42914
    nehakakar kakar
    Participant

    To redirect your WordPress website to SSL (HTTPS) using the .htaccess file and to include RewriteCond for server port, you can use the following code:

    RewriteEngine On
    
    # Redirect to HTTPS
    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    
    # Redirect to non-www
    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
    RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
    
    # RewriteCond for server port (example: redirect from port 80 to 443)
    RewriteCond %{SERVER_PORT} 80
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

    Make sure to place this code in the .htaccess file in the root directory of your WordPress installation.

    Here’s what the code does:

    1. The first block redirects all HTTP requests to HTTPS. If the request is made over HTTP (port 80), it redirects to the same URL using HTTPS (port 443).
    2. The second block removes the ‘www’ from the URL. If the request includes ‘www’ in the domain, it redirects to the same URL without ‘www’.
    3. The third block is an additional condition using RewriteCond for the server port. In this example, it redirects requests made on port 80 to HTTPS (port 443). Adjust the server port numbers as per your specific requirements.

    Please note that before making any changes to your .htaccess file, it’s always a good practice to create a backup of the original file. Additionally, if you have any existing code in your .htaccess file, make sure to place this code in the appropriate location, typically after the RewriteEngine On line.

Viewing 4 posts - 121 through 124 (of 124 total)
  • You must be logged in to reply to this topic.