Don't redirect in templates to other templates. That's not how templates work. Notice in your browser that you're never redirected to single.php or front-page.php or anything like that. If you do this then if you load a page that uses index.php your browser is going to redirect to http://website.com/front-page.php
and you'll get a 404.
Templates are loaded with include
(or require
) in PHP by WordPress to render the page as part of a process involving many WordPress files. They are not a loaded directly, and they are not redirected to.
The first thing to note for your specific example is that index.php is a required file for WordPress themes. So you can't delete it, and you shouldn't redirect from it. So if your front-page.php and index.php templates are the same, then you should be deleting front-page.php, not index.php.
You should start your theme with index.php, which should be the template for a generic list of posts. Then you start adding templates based on your design requirements, by referring to the Template Hierarchy and adding the ones you need.
However, let's say I have a custom post type whose archive template (eg. archive-project.php
) needs to be the same as the taxonomy archive template for its taxonomy (eg. taxonomy-project_category.php
). Both post type archives and taxonomy archives fall back to archive.php
. The problem is that if you're already using that for regular posts, you can't create a single template for both types of page.
The simplest solution is to load one template into the other using get_template_part()
. So archive-project.php
could be your main template, and then taxonomy-project_category.php
could look like this:
<?php get_template_part( 'archive-project' ); ?>