Add htaccess redirect code to Custom Code

Home Forums BulletProof Security Free Add htaccess redirect code to Custom Code

Viewing 15 posts - 1 through 15 (of 22 total)
  • Author
    Posts
  • #6761
    Steph Calvert
    Participant

    I know you get asked this all the time – I read this article http://forum.ait-pro.com/forums/topic/htaccess-redirect-code-where-do-i-add-redirect-htaccess-code/ and I’m having problems. Total BPS newbie here. I have a site I built at 3girlsholistic.com. They had an old page at 3girlsholistic.com/products that link doesn’t exist anymore, but is on their print materials so I absolutely need a redirect set up. It needs to go to: 3girlsholistic.com/all-green-shopping/natural-organic-skin-care What’s the redirect code to add, and exactly where do I add it? I hit the custom code button, I chose “root htaccess file custom code”, I scrolled down to this box:
    CUSTOM CODE BOTTOM HOTLINKING/FORBID COMMENT SPAMMERS/BLOCK BOTS/BLOCK IP/REDIRECT CODE: Add miscellaneous code here and entered this code:

    RedirectMatch 301 ^/products$ /all-green-shopping/natural-organic-skin-care/$1

    it’s not working – what am I doing wrong? Thank you in advance for your help!

    #6764
    AITpro Admin
    Keymaster

    When using RedirectMatch you need to include the entire/full URL to redirect too.  Also $1 is a backreference and in this case you would not want to use a backreference. Also be sure to add the last slash on the end of the the URL path otherwise you will get Soft 404 errors from Google.

    RedirectMatch 301 ^/products$ http://www.3girlsholistic.com/all-green-shopping/natural-organic-skin-care/
    #6768
    Steph Calvert
    Participant

    Thanks for getting back to me!

    I copied and pasted that exactly into the custom code bottom box, saved, still getting a 404 error. Do I need to do anything else in bps for this to take effect?

    #6772
    AITpro Admin
    Keymaster

    Yep, you would need to do some more steps.  The complete Custom Code steps are these (copied and pasted from the Blue Read Me help button on the Custom Code page):

    Root htaccess File Root Custom Code Setup Steps
    1. Enter your custom code in the appropriate Custom Code text box.
    2. Click the Save Root Custom Code button to save your custom code.
    3. Go to the BPS Security Modes page and click the Root Folder BulletProof Mode Activate button.

    wp-admin htaccess File Custom Code Steps
    1. Enter your custom code in the appropriate wp-admin Custom Code text box.
    2. Click the Save wp-admin Custom Code button to save your custom code.
    3. Go to the BPS Security Modes page and click the wp-admin Folder BulletProof Mode Activate button.

    #6773
    Steph Calvert
    Participant

    Thank you for the hand holding!! I got overwhelmed on the how to page because there’s a ton of code I didn’t fully understand. Much, much appreciated.

    #6774
    AITpro Admin
    Keymaster

    Yep, completely understand.  If you have never messed around with htaccess code it looks like complete gibberish.

    Regarding help info:  Our philosophy on providing help content is this.  Provide as much help content (mostly non-tech speak with some easy to understand tech speak) as possible in one centralized easily accessible location (Blue Read Me help buttons) that will answer most of the general questions that folks will have.  Trying to answer every possible question that could ever come up in the Blue Read Me help buttons is a bad idea so that is what this Forum is for.

    #25445
    Mariette
    Participant

    [topic has been merged into this relevant topic]
    Hello

    I have looked at your post http://forum.ait-pro.com/forums/topic/htaccess-redirect-code-where-do-i-add-redirect-htaccess-code/ for advice on where to put my existing redirects and, although the redirects I have set up in the past do seem to work, they are in a different format than you advise so I’m worried!

    Example of the redirect codes I have been using:

    Redirect 301 /about.html http://www.cranekalmanbrighton.com/about-ckb/
    Redirect 301 /rosa-basurto http://www.cranekalmanbrighton.com/photographer-category/contemporary-photographers/rosa-basurto/
    

    Should I be writing it like this instead?

    RedirectMatch 301 ^/about.html$ http://www.cranekalmanbrighton.com/about-ckb/$1
    RedirectMatch 301 ^/rosa-basurto$ http://www.cranekalmanbrighton.com/photographer-category/contemporary-photographers/rosa-basurto/$1
    

    I don’t want to change the hundreds of redirects and still get it wrong, and I am a little bit confused by the use of the $1 at the end of the redirect.

    Thank you for your help.
    best wishes
    Mariette

    #25450
    AITpro Admin
    Keymaster

    You can continue to use your existing htaccess redirect code.  The Redirect and RedirectMatch htaccess directives are the same except that RedirectMatch allows you to use Regular Expressions code.  Additional Note just for reference since you will be using your existing redirect htaccess code:  The $1 backreference would NOT be used in your example redirect code since you are redirecting to literal URL’s|links and NOT trying to splice URL’s|links.

    #30849
    C.A. Gross
    Participant

    [Topic has been merged into this relevant Topic]
    Hello.  I’d like to implement a simple 301 redirect by editing my .htaccess file, but I’m not sure exactly how to carry this out in BPS.  I’d like the page https://example.com/old/ to be redirected to https://example.com/new/  How would I use BPS to implement this 301 redirect, while ensuring to first make a backup of my htaccess file?

    My main issue is that I don’t know which .htaccess file to edit.  On my BPS “htaccess core” page, there appear to be five different htaccess files:

    1. secure.htaccess
    2. Your Current Root htaccess File
    3. wpadmin-secure.htaccess
    4. Your Current wp-admin htaccess File
    5. default.htaccess

    Thanks in advance.

    #30851
    AITpro Admin
    Keymaster

    You would use BPS Custom Code to save your Redirect htaccess code/rule.  Click the Read Me help button on the htaccess File Editor page for help info on what each File Editor tab/file does/means/is used for.

    1. Go to Custom Code, click the Root htaccess File Custom Code accordion tab.
    2. Paste your Redirect htaccess code in this BPS Root Custom Code text box: CUSTOM CODE BOTTOM HOTLINKING/FORBID COMMENT SPAMMERS/BLOCK BOTS/BLOCK IP/REDIRECT CODE
    3. Click the Save Root Custom Code button.
    4. Go to the Security Modes page, click the Root Folder BulletProof Mode Activate button.

    Example Redirect rule:

    RedirectMatch 301 ^/old$ https://example.com/new/
    #30854
    C.A. Gross
    Participant

    Thanks for this.  I will give it a shot.  I have a couple follow-up questions though:

    1. In the original post from this thread, a user seemed to have the same issue as me.  You directed that user to edit both the root htaccess and wpadmin htaccess.  But you’re advising me to only edit root htaccess.  Why is that?  I’m not arguing or accusing–I’d just like to learn a bit more.
    2. You’re telling me that I can’t actually change my htaccess file(s) in the “htaccess File Editor” tab.  If that’s the case, what is the purpose of that tab? If it’s for testing, would I be able to test my redirect in this tab before going live with it?

    Thanks.

    #30855
    AITpro Admin
    Keymaster

    1. I am answering your question specifically so I assume the other person had a different specific question.  This forum topic is a general topic about how and where to add htaccess Redirect code.  If you want some more advanced/in depth help info about htaccess Redirect code then take a look at this forum topic:  http://forum.ait-pro.com/forums/topic/htaccess-redirect-code-where-do-i-add-redirect-htaccess-code/

    2. Yep, exactly.  You can use the htaccess File Editor to add/test htaccess code/rules directly in your active/current Root htaccess file, which is this file > Your Current Root htaccess File tab.  To save your htaccess code permanently use BPS Custom Code after you are done testing your htaccess code using the htaccess File Editor.

    #30856
    C.A. Gross
    Participant

    OK thanks.  So just to be clear, to implement a simple 301 re-direct, I do *not* need to edit my wp-admin htaccess file in the wp-admin Custom Code text box?  I only have to do so for the root htaccess file?

    You can use the htaccess File Editor to add/test htaccess code/rules directly in your active/current Root htaccess file, which is this file > Your Current Root htaccess File tab.

    So if I add a proper 301 redirect code to “Your Current Root htaccess File,” are you saying I would be able to experience that redirect on my local machine, while users elsewhere would not experience the redirect?  If so, that would be very handy and I would like to use it.

    #30857
    AITpro Admin
    Keymaster

    The wp-admin htaccess file only affects things in the /wp-admin/ folder.  If you add a redirect rule it will affect everyone including you.  htaccess rules are literal.  You could of course add additional conditions to allow or not allow by IP addresses and then things would affect different IP addresses, but that is a more advanced lesson.  see this forum topic for more advanced htaccess redirect help and examples:  http://forum.ait-pro.com/forums/topic/htaccess-redirect-code-where-do-i-add-redirect-htaccess-code/

    #30858
    C.A. Gross
    Participant

    OK great, thanks so much for that link.  It looks like it will be very helpful. I’ll walk through it and post a new topic if I have a question.

    I now nearly understand the BPS features that are important to me.  But the htaccess File Editor sounds like it might be a very powerful testing tool, and I’d like to verify that.  The main question is:  Would I be able to test a 301 redirect before going live with it, using the htaccess File Editor?

    • If so, how would I approach that?
    • And what would ‘testing’ even mean in this case?  Does it mean that the 301 redirect would occur on my local machine, but not anywhere else?
    • It would be a very simple 301 redirect, with the page https://example.com/old/ being redirected to https://example.com/new/.

    Also, does BPS block other plugins from editing htaccess?  I have another plugin (Yoast SEO), which usually has a feature to edit htaccess.  But when I open it, that feature is missing.  I haven’t contacted them to ask about it, but I just thought I’d ask while I was here.

    Thanks again for all your help so far.  This is my first experience with BPS, and I’ll be sure to leave a positive rating on the WP page.

Viewing 15 posts - 1 through 15 (of 22 total)
  • You must be logged in to reply to this topic.