我有一个wordpress多站点安装,其中一个站点的URL从ppsdb.ppsri.org
更改为guide.ppsri.org
。我已经更新了数据库以反映这一点,并且新的URL可以正常工作。但我希望将旧URL的任何访问者重定向到新URL。我尝试将301重定向添加到.htaccess
,但它们似乎不起作用:
RewriteRule ^ppsdb.ppsri.org/(.*)$ guide.ppsri.org/$1 [R=301,NC,L]
访问ppsdb.ppsri.org
只是带我去注册网络中的新站点:http://ppsri.org/wp-signup.php?new=ppsdb
这是我完整的.htaccess
:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*\.php)$ $1 [L]
RewriteRule . index.php [L]
# redirect old Guide url traffic
RewriteRule ^ppsdb.ppsri.org/(.*)$ guide.ppsri.org/$1 [R=301,NC,L]
</IfModule>
# END WordPress
如何获取旧网址以转发到新网址?
答案 0 :(得分:1)
更新:通过将以下内容添加到.htaccess
的开头(在所有其他内容之前),我可以使其工作:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ppsdb\.ppsri\.org$
RewriteRule ^(.*)$ http://guide.ppsri.org/$1 [R=301,L]
</IfModule>
所以完整的.htaccess
是:
# redirect old Guide url traffic
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ppsdb\.ppsri\.org$
RewriteRule ^(.*)$ http://guide.ppsri.org/$1 [R=301,L]
</IfModule>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*\.php)$ $1 [L]
RewriteRule . index.php [L]
</IfModule>
# END WordPress