• I’m trying to redirect a page to a subpage from .htaccess.

    I put this in my .htaccess:
    redirect 301 /about https://www.site.com/about/about-me
    “About” is the parent page of “About me”.
    In browser I get this error “This webpage has a redirect loop”.

    I tried
    redirect 301 /about https://www.site.com/contact for testing purposes and it works.

    Any ideas?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Why are you trying to do this?

    Thread Starter silafu

    (@silafu)

    Because the parent page is an empty page with multiple subpages.

    I’m using wp-menus and i could add a custom link but I don’t want to loose the parent/child highlighting as the parent page has multiple subpages.

    Is there other solution than htaccess redirect or wp-redirect?

    Custom menu under Appearance in admin

    Another quick and easy solution. Install the Page Links To plugins

    Edit the About page, scroll to bottom, enter the absolute url to redirect the page to and save the changes. /about will now redirect to /about/about-me. The default setting is a 301. Works with pages and posts.

    That’s true!

    Thread Starter silafu

    (@silafu)

    Thanks for your tips.
    Installing a plugin just to achieve a couple of redirects doesn’t sound that good to me.
    I’m using custom menus but if I add a custom link that points “About” to “About me” i will loose highlighting of the parent page (current-page-ancestor class) when visiting “Contact” page (that is also a childpage of “About”)

    Installing a plugin just to achieve a couple of redirects doesn’t sound that good to me.

    The htaccess method sets up a loop, of course.

    Create an blank page template on your desktop and save it as aboutme.php. Paste this in it: (change the url for your own site, obviously)

    <?php
    /*
    Template Name: AboutMe
    */
    ?>
    <?php
    header("HTTP/1.1 301 Moved Permanently");
    header('Location: https://yoursite.com/about/about-me');
          die();
    ?>

    Upload aboutme.php to your current theme directory, then edit your About page and apply the new “AboutMe” template from the dropdown.
    Test the results.

    Not at all elegant, but I think it will work. Maybe someone will offer a cleaner version/solution.

    Thread Starter silafu

    (@silafu)

    Thank you ClaytonJames.
    I will use your solution but I would like to know why that htaccess redirect sets up a loop. It would be good for the learning process ??

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘.htacces redirect a page to a subpage’ is closed to new replies.