Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2017-11-18 23:47:51

neptho
Member
From: A cold, dark place.
Registered: 2006-02-01
Posts: 48

[Solved] Dynamic txp:site_url dynamic via trusted FQDNs?

Hello everyone.

(Read below to ensure it works for you- the answer for myself was to just unset Site URL)-

I can’t believe it’s been a decade since I visited (Last visit: 2007-02-02) the forums, but here I am again (guess I should eventually update my theme along with the code for a change)!

For the first time, I’ve decided to do something silly, and made my private TXP installation handle several TLDs that directly point to it with free LE certificates, because- why not?

Well, the problem I have is that site_url is static. I don’t really want to just use $_SERVER[‘SERVER_NAME’] for obvious reasons- but I also don’t want it redirecting to my primary domain. I’m not worried about SEO (this is for my old personal blog), but I also wouldn’t mind seeing them eventually reach some Google Cred™.

They’re all the same domain that have various different TLDs attached. Without rewriting things to use a homebrew not-site_url with trivial checking, are there any other suggestions of plugins or things that I might have missed? I searched the forums before posting my thread, but I don’t see anything that addresses this.

Thanks!

Last edited by neptho (2017-11-19 20:24:17)

Offline

#2 2017-11-19 09:41:44

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,293
Website GitHub

Re: [Solved] Dynamic txp:site_url dynamic via trusted FQDNs?

Hi and welcome back. Do the multi-site capabilities of recent releases help at all? You set one file installation and then point many databases at it. Each instance can have its own TLD.

Multi-site is going to be improved in the next release with luck, as there are still a few areas that need some love.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#3 2017-11-19 16:09:11

neptho
Member
From: A cold, dark place.
Registered: 2006-02-01
Posts: 48

Re: [Solved] Dynamic txp:site_url dynamic via trusted FQDNs?

Bloke wrote #307887:

Hi and welcome back. Do the multi-site capabilities of recent releases help at all? You set one file installation and then point many databases at it. Each instance can have its own TLD.

Multi-site is going to be improved in the next release with luck, as there are still a few areas that need some love.

Hi Bloke,

Thanks for your quick response!

The current multi-site capabilities do the opposite of what I actually intend-

I want multiple hostnames with my single db installation. There’s no real reason for it other than the fact I have several vanity domains that I have pointed to the same installation, and I’d prefer that they not all redirect to my primary txp:site_url without writing my own plugin for that. Simple and perhaps a bit naive, but I figured someone else would have done this by now. :)

<ObAside>
Thanks again to our small community of developers keeping TXP alive. I can’t imagine ever using another blogging tool. I’ll admit that I’ve forced myself to look at the latest “alternatives” such as Grav, Ghost, et al- but I could never live with them. ;)
</ObAside>

Last edited by neptho (2017-11-19 16:09:41)

Offline

#4 2017-11-19 16:23:43

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,293
Website GitHub

Re: [Solved] Dynamic txp:site_url dynamic via trusted FQDNs?

neptho wrote #307888:

The current multi-site capabilities do the opposite of what I actually intend-

Ah, my bad. I misunderstood your intentions. Mapping multiple hostnames to one installation is not the sort of thing I’ve ever tried so it’s out of my league, but maybe someone else has tried it and can offer some advice.

Thanks again to our small community of developers keeping TXP alive. I can’t imagine ever using another blogging tool. I’ll admit that I’ve forced myself to look at the latest “alternatives” such as Grav, Ghost, et al- but I could never live with them. ;)

You’re welcome. I too have strayed once or twice out of necessity but have not found anything as fun, flexible and powerful as building a Textpattern site.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#5 2017-11-19 17:12:12

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,615
Website

Re: [Solved] Dynamic txp:site_url dynamic via trusted FQDNs?

Hi and welcome back! As you’ve probably seen, it’s no problem to point multiple TLDs to the same textpattern installation, but as you say, the site_url is defined in the textpattern prefs, so one takes priority.

If you build your links in your code to not use txp:site_url or txp:permlink or one of the link="1" attributes in other tags that automatically constructs a link, the links within the site should stay within whatever domain name you arrived at the site with. For that you may need to alter link tags in your code to construct the path relative to the base /, e.g.

<!-- section link -->
/<txp:section />
<!-- category link -->
/<txp:section />?c=<txp:category />
<!-- permlink to article -->
/<txp:section />/<txp:article_url />
<!-- etc. -->

Note, though, that you might want to label just one of your domains as a canonical domain so that google doesn’t penalise you at some point for duplicate content at multiple TLDs. You could do that by using adi_variable to define your preferred domain (or just set it manually as part of your page head), and construct your rel=canonical links using that variable. For example, if you set a variable named canonical_domain, you would do:

<link rel="canonical" href="http://<txp:variable name="canonical_domain" />/<txp:section />/<txp:article_url />">

and so on for each page. Your actual page url might be different, but google should only log the preferred domain.

Other plugins that you might find useful include ied_if_domain and aam_if_host, which both allow you to include conditional content for different domain names.

One final word: I’m not sure how this works in conjunction with a certificate. If you get it working, pls report…


TXP Builders – finely-crafted code, design and txp

Offline

#6 2017-11-19 17:15:03

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,615
Website

Re: [Solved] Dynamic txp:site_url dynamic via trusted FQDNs?

PS: You and Stef joined the forum just a few days apart. I have a few more grey hairs than both of you, and Stef more posts than anyone else on the forum!


TXP Builders – finely-crafted code, design and txp

Offline

#7 2017-11-19 17:19:31

bici
Member
From: vancouver
Registered: 2004-02-24
Posts: 2,076
Website Mastodon

Re: [Solved] Dynamic txp:site_url dynamic via trusted FQDNs?

Can’t offer any help. but that theme of your blog LOL – it was my first TxP theme back in the day! I dont recall what it was called, but i ended up skinning i ta fair bit


…. texted postive

Offline

#8 2017-11-19 17:24:54

etc
Developer
Registered: 2010-11-11
Posts: 5,082
Website GitHub

Re: [Solved] Dynamic txp:site_url dynamic via trusted FQDNs?

One day I have left Site URL preference empty, and it worked for what I needed… don’t remember what it was, though.

Offline

#9 2017-11-19 17:25:39

neptho
Member
From: A cold, dark place.
Registered: 2006-02-01
Posts: 48

Re: [Solved] Dynamic txp:site_url dynamic via trusted FQDNs?

jakob wrote #307890:

One final word: I’m not sure how this works in conjunction with a certificate. If you get it working, pls report…
bq. PS: You and Stef joined the forum just a few days apart. I have a few more grey hairs than both of you, and Stef more posts than anyone else on the forum!

This is yet the other reason why I’m thinking of rebuilding a txp:site_url compatible plugin; I don’t force redirect from standard HTTP, but I want to also support HTTPS, which seems that it’d make more sense to outright build my own site_url based upon a set of valid hostnames, and dynamically construct http(s) as necessary. It used to depend on the browser, but they’re all migrating to non-https URLs as being untrusted, whether local, or not. IE really hates local references for HTTPS, and has since at least the 5.x days. Edge, I have no idea.

Great way to guilt me into feeling old and non-contributing! ;)

bici wrote #307892:

Can’t offer any help. but that theme of your blog LOL – it was my first TxP theme back in the day! I dont recall what it was called, but i ended up skinning i ta fair bit

It was called Connections . I keep thinking about fixing it and updating it, but it’s such a low priority that I generally just shrug it off. Heck, I haven’t owned the machine I cropped the header with for over a decade. :D

Last edited by neptho (2017-11-19 17:27:31)

Offline

#10 2017-11-19 17:37:13

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,615
Website

Re: [Solved] Dynamic txp:site_url dynamic via trusted FQDNs?

neptho wrote #307894:

Great way to guilt me into feeling old and non-contributing! ;)

;-) Sorry, just happened to spot it. Should have preceded that with “Fun fact:”.

This is yet the other reason why I’m thinking of rebuilding a txp:site_url compatible plugin.

I guess that wouldn’t be too complicated. You’d probably want to test against a list of permissible domain names. Is there any reason why constructing URLs without a protocol or domain should not work? I haven’t tested it conclusively, but I imagine it should work for either protocol and with whatever domain is currently in the address bar.

While I think of it, another aspect you’d probably need to check if you choose this avenue – aside from how links are constructed in your page templates – is links, and !image.jpg! links in your body fields. You’d need to likewise ensure they are not domain- or protocol-specific. You could do that by exporting your DB and searching and replacing within the sql file…


TXP Builders – finely-crafted code, design and txp

Offline

#11 2017-11-19 17:44:43

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,615
Website

Re: [Solved] Dynamic txp:site_url dynamic via trusted FQDNs?

Another thing that you might need to consider when directing multiple domains to the same installation is any domain-specific web services you may be using. For example, if you use typekit to serve webfonts, you need to add all your domains to your typekit kit settings for the webfonts to show on all of them.

(This probably doesn’t apply to your site, but I’m just noting this for future readers because I’ve made that mistake before).


TXP Builders – finely-crafted code, design and txp

Offline

#12 2017-11-19 17:48:50

neptho
Member
From: A cold, dark place.
Registered: 2006-02-01
Posts: 48

Re: [Solved] Dynamic txp:site_url dynamic via trusted FQDNs?

jakob wrote #307895:

;-) Sorry, just happened to spot it. Should have preceded that with “Fun fact:”.

No worries! I meant that in jest, and took it as fun as possible. :)

jakob wrote #307895:

I guess that wouldn’t be too complicated. You’d probably want to test against a list of permissible domain names. Is there any reason why constructing URLs without a protocol or domain should not work? I haven’t tested it conclusively, but I imagine it should work for either protocol and with whatever domain is currently in the address bar.

While I think of it, another aspect you’d probably need to check if you choose this avenue – aside from how links are constructed in your page templates – is links, and !image.jpg! links in your body fields. You’d need to likewise ensure they are not domain- or protocol-specific. You could do that by exporting your DB and searching and replacing within the sql file…

If you only use local references over HTTPS, browsers will complain like no tomorrow, and IE will fail to load every single resource, even with a “Yes” override, the last I checked. All HTTPS needs to be localized, and generally on the same domain depending on how locked down the browser is set- not that I’ve had anyone browsing my blog from a corporation for at least 15 years.

Your example otherwise is precisely what I am looking for, and why I figured it’d be easier to just do a replacement for the function, itself- but I don’t want to do that for a very good reason. Simple pseudocode would be like:

$myGoodSites = array("host1", "host2", "host3");  // Implement externally or in config.php
if (in_array($myGoodSites, strtolower($_SERVER['SERVER_HOST'])) !== FALSE) {
...  http/https detection here...
} else {
  return $txp_url;
}

Last edited by neptho (2017-11-19 17:51:13)

Offline

Board footer

Powered by FluxBB