Opened 9 years ago
Last modified 4 years ago
#36737 new defect (bug)
Single site reachable on multiple subdomains always redirected to site_url
Reported by: | jsoft | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 4.5 |
Component: | Canonical | Keywords: | reporter-feedback close |
Focuses: | Cc: |
Description
We run a site which is reachable by multiple subdomains (nb. not multisite) For example customer1.site.nl, customer2.site.nl. A plugin uses the subdomain to display different data for each customer. The site url is set to www.site.nl.
Since a recent update this stopped working. The visitor is always redirect to the site url www.site.nl.
I tracked down the problem to canonical.php. When I replace this file with the version from 4.4.2 the old behaviour is back, ie. the subdomains are not redirected.
There are no rewrite rules for these sub domains.
Change History (5)
#2
follow-up:
↓ 3
@
8 years ago
- Keywords reporter-feedback close added
Hi @jsoft, welcome to WordPress Trac!
We run a site which is reachable by multiple subdomains (nb. not multisite) For example customer1.site.nl, customer2.site.nl.
Could you provide some more details of your setup? Are there any filters used to modify the site URL on the fly?
Since a recent update this stopped working. The visitor is always redirect to the site url www.site.nl.
That's the exact purpose of canonical redirects, I don't see a bug here.
Here's the snippet I generally use in wp-config.php
to make a site available from multiple domains and avoid unwanted redirects to the primary domain:
define('WP_HOME', "http://{$_SERVER['HTTP_HOST']}"); define('WP_SITEURL', "http://{$_SERVER['HTTP_HOST']}"); ob_start( 'ob_replace_home_url' ); function ob_replace_home_url( $content ) { $home_urls = array( 'http://www.site.com', 'http://subdomain1.site.com', 'http://subdomain2.site.com', ); $content = str_replace( $home_urls, WP_HOME, $content ); return $content; }
Most of the time, just WP_HOME
and WP_SITEURL
would be enough to run the same install from multiple domains. The output buffering here just makes sure that URLs in content (images, etc.) always have the currently requested domain.
#3
in reply to:
↑ 2
@
6 years ago
Replying to SergeyBiryukov:
That's the exact purpose of canonical redirects, I don't see a bug here.
I was wondering about this myself - is it really the intention of redirect_canonical
to redirect from any domain to the main domain? Because a comment in the implementation seems to contradict this:
https://core.trac.wordpress.org/browser/tags/4.9.8/src/wp-includes/canonical.php#L460
The comment says: Only redirect no-www <=> yes-www
. Then the next few lines of code seem to be attempting to redirect only if the domains differ in having a www.
prefix. (But the code doesn't actually work because the logic is flawed.)
#4
@
4 years ago
@SergeyBiryukov what do you think?
https://core.trac.wordpress.org/browser/tags/4.9.8/src/wp-includes/canonical.php#L460
The comment says: Only redirect no-www <=> yes-www. Then the next few lines of code seem to be attempting to redirect only if the domains differ in having a www. prefix. (But the code doesn't actually work because the logic is flawed.)
Hi jsoft,
I have the same problem and I disabled the redirect_canonical:
I think this is a bad solution, but I do not know how best to resolve this situation.