I spent a bit of time today trying to research why Apache on Cpanel insisted on redirecting from index.php when it was entered as an explicit URL to the default index.html page in the website home directory.
As it turned out, while I am searching for “cpanel apache redirects” I should have been asking “Why does WordPress redirect…” and that change of question led me to this WordPress forum thread that addressed the actual issue.
Now normally I would not repeat the information here, but just in case that link disappears, I do want to be able to get to it again, so here it is.
The issue actually is not Apache or Cpanel driven, but is an issue with WordPress and the way that it redirects all requests to the home page for the site. Hence despite me trying to access index.php, WordPress was redirecting to index.html, and that prevented me from seeing the new WP site.
Ultimately the purpose of this was to allow for WordPress to be installed alongside an existing page based site and deploy for final user acceptance before switching off the old site and moving to WordPress as the new site.
The trick is simply a manually installed plugin that can be removed after final commissioning to production.
1. Open your site with an FTP program or SSH depending on you preference
2. Navigate to yoursite_folder/wp-content/plugins/
3. Create a new folder for the plugin – call it disable-canonical-redirects – or dcr for short
4. Change to that folder
5. Create a new index.php file and include (copy and paste or re-type) this PHP codeĀ into that file:
[text]
<?php
/*
Plugin Name: Disable Canonical URL Redirection
Description: Disables the "Canonical URL Redirect" features of WordPress 2.3 and above.
Version: 1.0
Author: Mark Jaquith
Author URI: http://markjaquith.com/
*/
remove_filter(‘template_redirect’, ‘redirect_canonical’);
?>
[/text]
5. Visit your WordPress Admin backend and activate this new plugin
6. All is now good to go and access index.html by default or index.php for WordPress explicitly.
Many thanks to Mark and others in that discussion thread.
Hi – yes I was struggling with this. And used your solution, but it works only if I create an .htacces file with this:
DirectoryIndex index.html index.php
Thanks anyway.
Tim
Hi Tim
Thanks for that feedback. I admit I have not touched this topic since I wrote the post and finished with that specific project. I’ve not needed it since, but from what you have logged it sounds like your Apache configuration has a different DirectoryIndex order that is ‘corrected’ by your .htaccess setting. I probably had the equivalent in my Apache config.
cheers
Tony
Thanks very much, works perfecly!