skip to Main Content

I would like to redirect the index.php to another file in my theme directory, but I get an error. about.php exists in the theme root directory, but it’s not a page template, so there is no reference to it in the database.

index.php

<?php

wp_redirect(get_site_url()."/about.php");
exit;

?>

Error

This page isn’t working
localhost redirected you too many times.
Try clearing your cookies.
ERR_TOO_MANY_REDIRECTS

What am I doing wrong?

2

Answers


  1. Chosen as BEST ANSWER

    I have found a solution using these guides:

    For anyone, who faces the same problem, just follow these steps:

    1. Create a single use page template with the page- prefix in the theme root directory. (e.g. page-about.php)
      • If you put <?php /* Template Name: About */ ?> to the top of the template file, it will be available for editors on the "New Page" interface as a page type. If you want to avoid that, just don't use this line.
    2. On the "New Page" interface, create a new page with the slug you prefixed with page- in the file name. (e.g. about)
    3. After these steps, Wordpress will know to load your template file, if you link it using the page's slug.
      • You can use the site_url() function to create a link. (e.g. <a href="<?php echo site_url("about"); ?>">About</a>)
      • Or you can use the wp_redirect() function to send the user to the desired page. (e.g. wp_redirect("about"); exit;)

  2. You can use this script for redirect to specific standalone test.php page of theme root directory. you need to use get_stylesheet_directory_uri() function because your PHP page exists in theme ROOT directory.

    wp_redirect( get_stylesheet_directory_uri()."/test.php" );
    exit;

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search