Contents
This page lists a number of important design decisions that come up frequently, and attempts to explain and cross-reference the reasoning behind them.
Absolute versus relative URLs #
WordPress stores absolute URLs in the database. Relative URLs are not used for a variety of reasons. Dynamically generated websites need permanent URLs (permalinks), so absolute URIs make more sense. WordPress has a variety of functions to call a site domain and various folders in plugins and themes so that relative URLs are not necessary. When moving domains, there are search and replace tools for switching domains in the database.
Why relative URLs are not good #
Content is migratory. That is to say that the content, which is in the database, might not always be displayed within the context of “your site”. Content can be displayed in a variety of places. For example, an RSS feed of your content can be pulled into Google Reader and displayed there. Or users can use feed readers of their own. Or the content can be pulled from your site using microformats and displayed somewhere else. A user will never know where the content is going to be. Therefore an absolute URL is necessary within that content to ensure that it always points to a specific point, regardless of where it’s displayed.
Permalinks are malleable. The content of a post can be displayed on http://example.com/, on http://example.com/archive/, http://example.com/2012/01/single-post, and so on. A relative URL would not be valid unless it is “root-relative”, meaning that it started with a / character, to refer to the root of the site. Even then, if a site is moved from one subdirectory to another, the root-relative URL would still need to change, and changing the content in the database to adjust would be necessary.
Moving is easier with absolute URLs. For example, assume a user is moving from http://foo.com to http://bar.com. Doing a search and replace in the database for “http://foo.com” and replacing that is very easy and unlikely to be problematic. One might say that a root-relative URL would not need to change at all in such a case, and this is true, but what if the content needs to be moved from http://foo.com/dev/ to http://bar.com? The root-relative URLs still need to change in such a case, and now there isn’t a simple to find string, such as “http://foo.com/dev/” to search and replace on.
Also, within the content of posts themselves, absolute URLs are easier to manage.
SSL and IP (load balance forwarding) #
Unfiltered HTML for editors, administrators; multisite #
Only owner-writeable is supported on upgrade, not group writeable #
Some esoteric MySQL settings are not supported #
WordPress does not support MySQL strict mode or autocommit = 0. #8857, #16821, #16429.
Mayeenul Islam 10:01 am on September 4, 2012 Permalink | Log in to Reply
I’m afraid it may not fit with the post, but I want to contribute with opinion and knowledge if I have any:
It creates a problem like, after a while maintaining other works simultaneously I returned to that page, and wonder is that the second update notice, or saying about the first update? Did I click “update” button after the second edit?
PROBABLE SOLUTION:
(a) This nag update will appear for 3/5 mins or less. And then will disappear. So then the user will understand, if he/she did any edit after the previous save/update.
or,
(b) There will be a close button just right to the nag update div, so that the user will turn it down if he/she feels so.
Thanks.
tblanchard 6:14 pm on January 2, 2013 Permalink | Log in to Reply
I notice the section SSL and IP load balancing is blank. Having implemented this using a load balancer/proxy that has the security certificate and then forwards requests to servers as http I think I can see why.
Looking at my half rendered WP page, I find that many URLs for scripts and css files start with http: although my content all starts with https: since I configured the site to use that via admin.
This problem would be solved by switching to using protocol-less URLs as defined in RFC 3986 part 4.2. The gist of this is that any file referenced in a page without a protocol – eg //www.example.com instead of http://www.example.com – would be fetched using the protocol of the enclosing page.
I wouldn’t consider this such a problem if url generation were consistent, however efforts to get my site working show that it isn’t by any stretch of the imagination consistent. It is all over the map. Some code looks at database settings, some looks at $_SERVER
sethmatics 9:11 pm on January 14, 2013 Permalink | Log in to Reply
I read this as it jumped out at me. I prefer to NOT use absolute URL’s, for a number of reasons. I do see the benefit to absolute URL’s as described here, especially given that “content may not be displayed on just your site”. However, with considering to migrations there becomes a huge problem with “search and replace” functions as they relate to “serialized options” containing absolute URL’s. When you serialize an option, you define the length of the string, and when you search and replace, you corrupt the serialized string because the length no longer matches. Can you give us any insight to this issue?
sethmatics 9:12 pm on January 14, 2013 Permalink | Log in to Reply
Sorry for the grammar mistakes, i couldn’t edit after I published
almart 3:35 pm on June 5, 2013 Permalink | Log in to Reply
I noticed that, 5 months later, the SSL and IP load balancing problem is still blank.
Having implemented this using a load balancer/proxy that has the security certificate and then forwards requests to servers as http I think I can ALSO see why.
I want to make a line by line retort to the “Absolute versus relative URLs” section:
“Dynamically generated websites need permanent URLs (permalinks)”
Why? Just.. why? The use of permalinks in WP is overpriced and too much used. Permalinks are easy to build but a pain to replace. It’s an anti-pattern. They were designed for and should only be used for referring to an external URI.
“When moving domains, there are search and replace tools for switching domains in the database.”
Cool feature
“Content is migratory”
…so relative URLs are a much better choice.
“Content can be displayed in a variety of places. For example, an RSS feed of your content can be pulled into Google Reader and displayed there.”
Right. And RSS feeds can be made to be have absolute links (those you love) as it is content meant to be reached from another site or by a client. I’m cool with that.
“Therefore an absolute URL is necessary within that content to ensure that it always points to a specific point, regardless of where it’s displayed.”
YES. THAT content. Not every other. Just content which is intended to be consumed from outside. Every other content should be relative. If someone, somewhere, wants to fetch content from a site for whatever reason, then it’s up for him (or her) to make an absolute URI out of a relative one.
“A relative URL would not be valid unless it is “root-relative”, meaning that it started with a / character, to refer to the root of the site. Even then, if a site is moved from one subdirectory to another, the root-relative URL would still need to change, and changing the content in the database to adjust would be necessary.”
Agreed to the root-relative part. The site moving from a subdirectory to another… that’s not so common as the domain change. I would say it’s marginal, compared to the domain change. And root-relative URIs are just as easy to change as domain names, so I’d say this is a stupid reason to write in a handbook.
“Also, within the content of posts themselves, absolute URLs are easier to manage.”
I can’t imagine why.
In the past I’ve seen this absolute-uri-because-of-yes feature as a nuisance, and a wrong thing to do. Now I’m quite pissed of it. I’ve hundreds of WP to reverse (ssl) proxy and I can’t make changes in any of them.
PLEASE follow tblanchard’s directions at least (even if WP keeps working on an anti-pattern) and make URI’s protocol-relative.
T.I.A.
almart 8:48 am on June 6, 2013 Permalink | Log in to Reply
The “cool feature” part had some sarcasm tags on it that were unkindly and unadvertedly supressed.
aymanp 11:00 pm on June 10, 2013 Permalink | Log in to Reply