WordPress SSL htaccess code – Rewrite SSL, RewriteCond Server Port

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

Viewing 5 posts - 121 through 125 (of 125 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

    #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.

    #44878
    sebastian
    Participant

    Hi,
    I have a problem with my htaccess code

    in the custom area, before I installed BPS ( pro) everything was still working fine :)), I’ve been around for a long time, but I’ve never really warmed up to regular expressions, htaccess etc. It would be great if one of you could tell me where to insert the code so that it works again.

    Maybe not useless to understand, if someone enters website.org/vibifx, he should be redirected to:
    http://www.website.org/home/found/?vibifx

    I just can’t get it to work…

    my .htaccess:

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^website\.org [NC]
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteCond %{REQUEST_URI} ^/([a-zA-Z0-9]+)$
    RewriteCond %1 !=home
    RewriteRule ^(.*)$ http://www.website.org/home/found/?foundid=%1 [R=301,L]

    Hope you understand my problem & thanks in advance

    Sebastian

    #44880
    AITpro Admin
    Keymaster

    I don’t have enough info to help you.  I tried going to the destination redirect URL and it goes to the same generic hosting page.  Explain in detail what you are trying to do.

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