WordPress.org

Ready to get started?Download WordPress

Forums

BulletProof Security
[resolved] 301 redirect - Bulletproof Security (2 posts)

  1. elmatinal
    Member
    Posted 3 years ago #

    Hello! I've been using the Bulletproof Security plugin for a while now, and am very happy with it. However, I realized I needed a 301 redirect, since my domain seems to have two entries on Google (with and without www.).

    I've edited the .htaccess (via BPS in dashboard) and it worked fine for a few minutes, then it just stopped working. I went to the dashboard and the 301 redirect code was still in the .htaccess file, but it just didn't work.

    In fact, it's still there and I have made no modifications, I just can't understand why it just worked a few minutes then not anymore.

    This is the code I've used:

    RewriteCond %{http_host} ^mydomain.com\.com [nc]
    RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=permanent,nc,L]

    Of course, I've replaced my actual domain name :P

  2. AITpro
    Member
    Plugin Author

    Posted 3 years ago #

    You can set the domain name in WordPress Settings >>> General, but if you already have pages out there and you want them to redirect whether they have the www prefix of not you could use either examples below depending on what you want to do. The htaccess code you posted is not valid.

    Permanently redirect all non-www requests to www domain
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

    Permanently redirect all www requests to non-www domain
    RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
    RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]

    or another way without having to add the host name
    RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
    RewriteRule ^(.*) http://%1/$1 [R=301,L]

    Thanks
    Ed

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic