我有一个在WordPress中有5个域的多站点网站,它使用WordPress MU域映射插件。
我想将每个子页面重定向到新域,但我们仍将使用主页,因为其中包含一些链接,所以root,wp-admin
和wp-login
, 仍应可访问,且不应重定向。如何在中设置.htaccess
那么WordPress仍将发挥作用?
域示例:
oldone.com/ --> no redirection
oldone.com/wp-admin --> no redirection
oldone.com/wp-login --> no redirection
oldone.com/about --> newone.com/about
oldone1.com/about --> newone1.com/about
... etc ...
.htaccess
:
RewriteEngine On
RewriteBase /
RewriteRule ^index\\.php$ - [L]
# uploaded files
RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^[_0-9a-zA-Z-]+/(.*\\.php)$ $1 [L]
RewriteRule . index.php [L]
### oldone.com redirect
RewriteCond %{HTTP_HOST} ^oldone.com$ [NC]
#redirects domain.com to www.oldone.com
RewriteRule ^(.*)$ http://oldone.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www\\.oldone.com\\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/(wp-login/?|$)
RewriteCond %{REQUEST_URI} !^/(wp-admin/?|$)
RewriteRule ^(.*)$ http://newone.com/$1 [R=301,L]
####
SO网友:DocRoot
尝试在.htaccess
文件:
RewriteCond %{HTTP_HOST} ^(www\\.)?oldone\\.com
RewriteCond ${REQUEST_URI} !^/wp-admin
RewriteCond ${REQUEST_URI} !^/wp-login
RewriteRule . http://newone.com%{REQUEST_URI} [R,L]
确保浏览器缓存已清除。只有当您确定它工作正常时,才更改为301(如果这是您的意图)。
对任何其他对象重复此操作oldoneN.com
/ newoneN.com
组合,除非有域名模式?
或者,如果您从不想重定向/wp-admin
或/wp-login
对于任何域,那么您可以为这些URL路径包含一个异常。尽管这可能会干扰其他一些MU指令。