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

customization - Turn off redirect to canonical domain (or host website on any hostname)

programmeradmin1浏览0评论

I want to have various development (say dev.example) and staging environments of a WordPress multisite (example). For this it would be great if WordPress wouldn't redirect to what it considers the canonical domain name.

I'm running into trouble with this in my wp-config.php:

define('DOMAIN_CURRENT_SITE', gethostname());

It redirects to example or gives me database errors.

This is after wp search-replace example dev.example.

Is it possible to turn off this redirection? If so, how?

I want to have various development (say dev.example) and staging environments of a WordPress multisite (example). For this it would be great if WordPress wouldn't redirect to what it considers the canonical domain name.

I'm running into trouble with this in my wp-config.php:

define('DOMAIN_CURRENT_SITE', gethostname());

It redirects to example or gives me database errors.

This is after wp search-replace example dev.example.

Is it possible to turn off this redirection? If so, how?

Share Improve this question edited Jul 24, 2019 at 21:53 the asked Jul 5, 2019 at 17:54 thethe 1,5682 gold badges13 silver badges32 bronze badges 3
  • gethostname()) can't be asked from wp-config.php. It's too early. Try init or, depends of configuration, something later. Use a plugin, e. g. Debug Bar plus Debug Bar Action Hooks to watch what happens early and what happens later. – Max Yudin Commented Jul 5, 2019 at 19:28
  • echo gethostname(); exit(); in wp-config.php looks fine to me. But I'll try Debug Bar Action Hooks to see if I can hook around the redirect. – the Commented Jul 6, 2019 at 9:26
  • exit(); in wp-config.php is very bad idea. No WordPress environment in this case. – Max Yudin Commented Jul 6, 2019 at 17:18
Add a comment  | 

2 Answers 2

Reset to default 1 +50

In addition to modification of wp-config you might need to check .htaccess too, if there are any pointers to subfolder.

After that, you might need to replace the values in DB tables wp_site and wp_blogs.

From: Velvet Blues

To turn off Canonical URL Redirection, you can add the following code to your theme’s functions.php file.

remove_filter('template_redirect','redirect_canonical'); 

or use the plugin: Disable Canonical Redirects Plugin

发布评论

评论列表(0)

  1. 暂无评论