Skip to content
Advertisement

Redirect only WordPress homepage with a 301 redirect

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.

What I want is to redirect example.com homepage only to example.com/np. It would be great if that redirection is a 301 moved permanently redirection.

If I place the 301 redirection in WordPress header file, header.php, it will redirect every page. And if I check if the page is home and try a 301 redirection that’s not possible because header redirection should be placed at top.

How to achieve this?

Advertisement

Answer

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.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement