0

I came across this site and I was wondering why WordPress isn't using this as default:

define('WP_SITEURL', 'http://' . $_SERVER['SERVER_NAME']);
define('WP_HOME',    'http://' . $_SERVER['SERVER_NAME']);

So nobody has to change this values when changing the domain. Is there any reason or disadvantages of using this?

0

With these constants defined, your WP site will work both with and without the preceding www. (as well as on any other URLs that correctly resolve to the site, like hosting-provided staging URLs, etc), which search engines will penalize as duplicate content.

5
  • well, but how to prevent this? I cant see the difference to define('WP_SITEURL', 'http://www.example.com'); (except the dynamic url)
    – maysi
    Jan 24 '15 at 17:08
  • 1
    you can prevent this by not using these constants, instead defining it using the fields under Settings > General as intended. Jan 24 '15 at 17:11
  • but when I use Settings → Preferred domain in the Google Webmaster tools I won't have these problems. Am I right?
    – maysi
    Jan 24 '15 at 17:15
  • based on my admittedly limited understanding of it, yes - I believe that is correct. Jan 24 '15 at 17:20
  • ok. thanks :) 1 last question: When I use $_SERVER['SERVER_NAME'] but remove the possible www. with str_replace() it would work without penalization?
    – maysi
    Jan 24 '15 at 17:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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