Thanks in advance for any help provided.


  1. Debian Jessie
  2. Front-end Nginx (1 server, 2 server_names; rewrites working correctly),
  3. Proxied back-end Apache with no rewrites/aliases and other,
  4. WordPress installed in /var/www/www.test.blog/wordpress/ with no plugins,
  5. No constants declared in wp-config.php.

I'm trying to make WP being resolved from multiple GET URLs:
test.blog and www.test.blog.

Due to Apache logs everything goes just fine until requesting reaches /var/www/www.test.blog/wordpress/index.php (line:18), after which, suddenly, appears response 301 to test.blog (line:19)

01:Request received from client: GET /wordpress/ HTTP/1.0
02:Headers received from client:
05:Host: www.test.blog
06:Connection: close
07:User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36
08:Upgrade-Insecure-Requests: 1
09:Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng
10:DNT: 1
11:Accept-Encoding: gzip, deflate
12:Accept-Language: ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7
13:authorization result of Require all granted: granted
14:authorization result of <RequireAny>: granted
15:request authorized without authentication by access_checker_ex hook: /wordpress/
16:authorization result of Require all granted: granted
17:authorization result of <RequireAny>: granted
18:request authorized without authentication by access_checker_ex hook: /wordpress/index.php
19:Response sent with status 301, headers:
20:Date: Fri, 26 Jan 2018 14:20:49 GMT
21:Server: Apache/2.4.10 (Debian)
22:Location: http://test.blog/wordpress/
23:Content-Length: 0
24:Connection: close
25:Content-Type: text/html; charset=UTF-8

Can it be that WP itself makes any redirect via PHP? I mean, it's totally capable of it, but does it happen actually (as I have no other suspects)?
And if, what should I do to stop this behavior & finally make it being resolved from multiple URLs?

  • What are Home URL and Site URL set to in the settings?
    – swissspidy
    Jan 26, 2018 at 17:29
  • This is how WordPress is supposed to work if you've configured rewrite rules in your nginx.conf - requests to index.php are redirected and handled by WordPress. Is the redirect resulting in you ending up at the wrong page?
    – phatskat
    Jan 26, 2018 at 17:44
  • @swissspidy, they are not set on purpose. I was hoping to prevent WP this way from making own rewrites...
    – Denis.Z
    Jan 26, 2018 at 20:12
  • @phatskat, well, I've not seen anywhere info, saying that WP is intended to make own rewrites. It seems even wrong WP making own "black boxed" rewrites...
    – Denis.Z
    Jan 26, 2018 at 20:15
  • @phatskat, actually, yes, instead of keeping host www.test.blog, WP seems to change it to test.blog. Also it makes new URL visible, changing it in adress bar... I still get target page, but like test.blog/wordpress/wp-admin... instead of requested www.test.blog/wordpress/wp-admin... And it drives me a bit mad, as I didn't want URL to change...only redirected behind the scenes...
    – Denis.Z
    Jan 26, 2018 at 20:23

1 Answer 1


It sounds like both Home URL and Site URL for your blog are set to http://test.blog, while your server accepts both http://test.blog and http://www.test.blog.

If you access the latter, WordPress will redirect you because of the mismatch. You might be able to set the Home URL and Site URL dynamically in your wp-config.php like this:

define( 'WP_SITEURL', 'https://' . $_SERVER['HTTP_HOST'] );
define( 'WP_HOME',    'https://' . $_SERVER['HTTP_HOST'] );

This way, there shouldn't be a redirect. But this has of course complications for things like URLs in post content. WordPress does not use relative URLs for that. That's why it's generally better to settle one 1 domain. But there are also other reasons like SEO (duplicate content). Your web server should either redirect www.test.blog to test.blog or vice-versa, it's the easiest way to solve this. The site will obviously still be available via either host, it's just that you have to settle for one.

Note: $_SERVER['HTTP_HOST'] is not set on the command line, so if you want to use WP-CLI you'd have to set that variable.

Please let me know if that answers your question or if I misunderstood you.

  • Yep, seems you're got it even better than I could expect :) Much obliged for the link you've given, I'll examine the material. Great thanks for specifying those defines - I'm so clumsy with these global variables... Seems I really should settle for 1 domain as good practice. I've just got overwhelmed with ideas, while being a total stranger with SEO...
    – Denis.Z
    Jan 29, 2018 at 8:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.