简体   繁体   中英

Redirect Wordpress index.php

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?

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;

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. (eg 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. (eg 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. (eg <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. (eg wp_redirect("about"); exit; )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM