最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to tweak page links in Wordpress Multisite

programmeradmin2浏览0评论

I have a Wordpress multisite configuration like this:

  • www.domain/ -> Primary site (not used)
  • www.domain/de-de/ -> German site
  • www.domain/en-us/ -> English site

However, for reasons unrelated to Wordpress, I need that the network sites have this layout:

  • www.domain/de-de/blog/ -> German site
  • www.domain/en-us/blog/ -> English site

Unfortunately, you cannot define a site as de-de/blog in your WP network because the forward slash is not an allowed character for a site name.

Therefore, I tried defining a reverse proxy like this on Apache:

ProxyPreserveHost On
ProxyPass        "/de-de/blog/" "http://127.0.0.1/de-de/"
ProxyPassReverse "/de-de/blog/" "http://127.0.0.1/de-de/"
ProxyPass        "/en-us/blog/" "http://127.0.0.1/en-us/"
ProxyPassReverse "/en-us/blog/" "http://127.0.0.1/en-us/"

This seems to do the trick for site routing, but in the returned page, the internal URLs in the HTML page are www.domain/de-de/, not www.domain/de-de/blog/

How could I have WP in multisite mode use URL layout from upstream (i.e. www.domain/de-de/blog/) in the rendered HTML pages?

I have a Wordpress multisite configuration like this:

  • www.domain/ -> Primary site (not used)
  • www.domain/de-de/ -> German site
  • www.domain/en-us/ -> English site

However, for reasons unrelated to Wordpress, I need that the network sites have this layout:

  • www.domain/de-de/blog/ -> German site
  • www.domain/en-us/blog/ -> English site

Unfortunately, you cannot define a site as de-de/blog in your WP network because the forward slash is not an allowed character for a site name.

Therefore, I tried defining a reverse proxy like this on Apache:

ProxyPreserveHost On
ProxyPass        "/de-de/blog/" "http://127.0.0.1/de-de/"
ProxyPassReverse "/de-de/blog/" "http://127.0.0.1/de-de/"
ProxyPass        "/en-us/blog/" "http://127.0.0.1/en-us/"
ProxyPassReverse "/en-us/blog/" "http://127.0.0.1/en-us/"

This seems to do the trick for site routing, but in the returned page, the internal URLs in the HTML page are www.domain/de-de/, not www.domain/de-de/blog/

How could I have WP in multisite mode use URL layout from upstream (i.e. www.domain/de-de/blog/) in the rendered HTML pages?

Share Improve this question asked May 10, 2020 at 21:40 PepPep 5631 gold badge4 silver badges5 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

I fixed it changing the urls of the sites to include the /blog/ suffix. You cannot create the site with a slash but you can change the site URL once it is created.

Then changing the RewriteRules in .htaccess to:

RewriteRule ^([_0-9a-zA-Z-]+/blog/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteRule ^([_0-9a-zA-Z-]+/blog/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/blog/)?(.*\.php)$ $2 [L]

Finally, adding some code to wp-config.php to properly define the PATH_CURRENT_SITE and BLOG_ID_CURRENT_SITE variables:

define('PATH_CURRENT_SITE', $path_current_site);
define('BLOG_ID_CURRENT_SITE', $blog_id_current_site);
发布评论

评论列表(0)

  1. 暂无评论