更新时间:2022-10-15 08:40:38
您不想要要为此混入您的Wordpress模板或代码,只需在您的 .htaccess
中使用单个mod_rewrite规则:
RewriteRule / / np [R = 301,L]
如果它已经在 RewriteEngine on
行下面,请将其添加为单独的行,然后将其添加到 RewriteRule
行之上。 / p>
此解决方案易于删除,易于维护,可移植,并且比在PHP中的模板或WP代码中执行的性能更好,并且可以保留对模板的更新。
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?
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.