htaccess Redirect Code – Where Do I Add Redirect htaccess Code

Home Forums BulletProof Security Pro htaccess Redirect Code – Where Do I Add Redirect htaccess Code

Viewing 15 posts - 16 through 30 (of 32 total)
  • Author
    Posts
  • #30576
    jenni101
    Participant

    Just tried a range of permutations of the above code; with and without the ‘/’ and with and without the $1 at the end like you had it, and still no luck.

    It always just loads the page as normal, not going to the redirected one (no 404 errors now, as I’d forgotten that I had them set to privately published).

    Is it because the pages are all on the same site? As I’d copied all the old pages to the new site, and am now putting in the redirects on the new site for it’s own pages.

    I don’t knwo why I’m strugging with this as it should be pretty straight forward I think! hey-ho… I’ll keeping trying different options and will post back if/when I can get it to work.

    Thanks again.

    #30577
    jenni101
    Participant

    Still no success with any of my internal or external redirects.

    Would it make a difference having a site in it’s own folder – ie. being a GWIOD site? Like should these redirects go in the root htaccess instead?… just a thought anyway.

    Also after lots more reading and searches, there’s also info in this forum about putting the redirects in the # WP REWRITE LOOP  area: http://forum.ait-pro.com/forums/topic/redirect-to-new-domain-and-new-url-structure/

    Your thoughts appreciated on this. many thanks.

     

    #30578
    jenni101
    Participant

    OK, I can confirm the code you wrote last works for my current (live) old site. So must have something to do with how redirects work when the DNS isn’t configured to the current site. So I’ll be able to check them in my new site all when it goes live. Thank you!

    So just a couple of things that I don’t understand in the redirect code, that I’ve seen used:

    what is the difference in using this:

    Redirectmatch 301 ^/competitions/$ http://www.my-site.com/

    compared to this?

    Redirectmatch 301 ^/competitions(.*)$ http://www.my-site.com/

    And when would you use the redirect in # WP REWRITE LOOP format, rather than in the bottom custom code box?

    Thank you.

    #30579
    AITpro Admin
    Keymaster

    Yep, redirects will not work until DNS Propagation is finished.  The first redirect rule will only redirect this match:  /competitions/ to somewhere else.  The second redirect rule is using (.*), which means match anything.  Let’s say you have 2 URI’s|URL’s with these names:  /competitions-bowling/ and /competitions-golfing/.  Since your redirect rule says to match anything after: competitions then your rule would match both of these URI’s|URL’s and would redirect both of these URI’s|URL’s to the same place.  This particular Redirect Rules/code can go anywhere.  They are independent/stand-alone htaccess code/rules.  So basically adding Redirect Rule htaccess code to the bottom Custom Code text box is just for organization. ie keep related code in the same place.  If you have sites (child sites, subdomains, etc) you need to skip/bypass then you would use RewriteRules in the WP Rewrite Loop block of code so that the RewriteRules are processed first before being sent through the BPS Query String block of code.  They are htaccess skip/bypass rules.

    #30925
    C.A. Gross
    Participant

    [Topic has been merged into this relevant Topic]
    Hello.  I just tried to implement my first simple 301 redirect, but it is not redirecting as expected.  The goal of the 301 redirect is to direct people visiting: https://www.horizonhomes-samui.com/horizon-homes-construction/ to the new page of https://www.horizonhomes-samui.com/construction/

    The code I inserted is:
    Redirect 301 /horizon-homes-construction/ https://www.horizonhomes-samui.com/construction/
    I have been following the instructions here: http://forum.ait-pro.com/forums/topic/htaccess-redirect-code-where-do-i-add-redirect-htaccess-code/, but I did not use a RedirectMatch.  Is that necessary?

    Thanks!

    #30929
    AITpro Admin
    Keymaster

    Using the RedirectMatch directive htaccess code is better to use in general because it allows you to use Regular Expressions (RegEx) code such as ^ and $, which without going too deep technically is just a way to make the htaccess code more versatile|flexible.  The Redirect directive is more restrictive since you cannot use RegEx code with “Redirect”.

    So try this code and just make sure you are doing all the Custom Code steps fully.

    RedirectMatch 301 ^/horizon-homes-construction/$ https://www.horizonhomes-samui.com/construction/
    #30947
    C.A. Gross
    Participant

    Thanks so much for that.  OK I see now why RedirectMatch is more advantageous (with RegExp support).  But I tried inserting your suggested code and I’m still encountering the same issue.  When I visit the old blog post, I am not redirected to the new page.  I am following the steps in this guide, namely:

    1.  Add the code to the CUSTOM CODE BOTTOM HOTLINKING/FORBID COMMENT SPAMMERS/BLOCK BOTS/BLOCK IP/REDIRECT CODE field.
    2. Click the Save Root Custom Code button.
    3. Go to the BPS Security Modes page and click the Root Folder BulletProof Mode Activate button.

    The code is indeed added because I can view my current htaccess file and visually confirm that the same code is present in the correct area.  How should I proceed?

    #30948
    AITpro Admin
    Keymaster

    There is only one other possibility that I can think of if you are sure you have added the redirect code correctly and that is your host requires that you use the folder name where the site is installed.  Example:  If the folder name is: /horizonhomes-samui.com/ then your redirect code would be:  RedirectMatch 301 ^/horizonhomes-samui.com/horizon-homes-construction/$ https://www.horizonhomes-samui.com/construction/.

    If that does not work then you will need to contact your host to find out why this simple redirect code is not working on your site. Adding redirect code is a very basic simple straight forward thing some other factor is interfering with this code.

    #30960
    C.A. Gross
    Participant

    OK thanks.  I tried your latest suggestion but the redirect still isn’t occurring.  I will speak with my server admin and see what is happening, thanks.

    #31065
    C.A. Gross
    Participant

    @AITpro Admin just to update you, the issue turned out to be that my site is on an Nginx server, so any redirects added to htaccess will not be read.

    #31066
    AITpro Admin
    Keymaster

    @ C.A. Gross – See these 2 links below for how to create Nginx rewrite/redirect rules.

    https://www.nginx.com/blog/creating-nginx-rewrite-rules/

    https://codex.wordpress.org/Nginx

    #31101
    webstar
    Participant

    [Topic has been merged into this relevant Topic]
    I just want to add a simple redirect line in my htaccess. Where do I put that in the custom code?

    Code will be:

    Redirect 301 /oldfile.htm /newfile.htm

    Thanks.

    #31103
    AITpro Admin
    Keymaster

    @ webstar –

    1.  Add your redirect .htaccess code to this BPS Custom Code text box: CUSTOM CODE BOTTOM HOTLINKING/FORBID COMMENT SPAMMERS/BLOCK BOTS/BLOCK IP/REDIRECT CODE
    2. Click the Save Root Custom Code button.
    3. Go to the BPS Security Modes page and click the Root Folder BulletProof Mode Activate button.

    #31673
    simon
    Participant

    [Topic has been merged into this relevant Topic]
    Hi,
    how can i add a rewrite rule to the htacces?
    Thanks Simon

    #31677
    AITpro Admin
    Keymaster

    @ Simon – See the beginning of this forum topic for how and where to add htaccess code to BPS Custom Code.  If you post the custom htaccess code you want use I can tell you exactly which BPS Custom Code text box it should be added to.

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