I have a blog, lets say example.com
and another blog installed in example.com/np
which is not multisite but a different WordPress installation.
Put the following in your functions.php
file:
add_action( 'get_header', 'so16738311_redirect', 0 );
function so16738311_redirect()
{
if( is_home() || is_front_page() ) {
wp_redirect( home_url( '/np/' ), 301 );
exit;
}
}
You can use wp_redirect function of WordPress with status code. add Follwing code on wordpress init hook
if ( is_home() ) {
wp_redirect( $location, $status );
exit;
}
Just put this at the very top of your index.php
file of your wordpress installation:
if($_SERVER['REQUEST_URI'] == "/"){
include('......server file directory to file you want to redirect to');
exit;
}
Since you're in the context of WordPress, you can utilize its redirect functionality.
Like this ( in functions.php ):
function redirect_homepage() {
if( ! is_home() && ! is_front_page() )
return;
wp_redirect( 'http://redirect-here.com', 301 );
exit;
}
add_action( 'template_redirect', 'redirect_homepage' );
You don't want to muddle in your Wordpress templates or code for this, just use a single mod_rewrite rule in your .htaccess
:
RewriteRule / /np [R=301,L]
Put it below the RewriteEngine on
line if it's already there, else add it as a separate line above the RewriteRule
line.
This solution is easily removable, easily maintainable, portable, and performs better than doing it in PHP in the templates or WP code, and survives updates to your templates.
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule (.*) http://www.Your domain/$1 [R=301,L]
</IfModule>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress