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
I have found a solution using these guides:
For anyone, who faces the same problem, just follow these steps:
page-
prefix in the theme root directory. (e.g.page-about.php
)<?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.page-
in the file name. (e.g.about
)site_url()
function to create a link. (e.g.<a href="<?php echo site_url("about"); ?>">About</a>
)wp_redirect()
function to send the user to the desired page. (e.g.wp_redirect("about"); exit;
)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;