Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2019-10-13 20:38:24

detail
Member
From: geez, I seem to be in NZ
Registered: 2010-07-13
Posts: 141
Website

404 woes with .htaccess coding

Recently I finally changed my third website from http to https.

For some reason I found I had bought the security certificate under a non-www domain, and rather than change the certificate, I changed the preferences in Textpattern to be non-www.

This is the .htaccess coding that is used to affect the https:

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(bluelake\.co\.nz|nelsonbuildingreports\.co\.nz|tramping\.net\.nz)$
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

This tramping\.net\.nz was what I added a week ago.

Explanation here. I am using a multi-site hosting where I have one main site and a few others that are hosted as sub-domains, but are actually completely different websites with their own unrelated domain names. These are housed in their own folders within the parent website.

Confused? Well, this has worked well for 9 years.

Since the change I am getting a number of 404 notices in my log. Maybe only one in 10 or so. I haven’t suffered any major loss of hits.

These are all due to the folder name being added to the address.

https://tramping.net.nz/tramping/blog/

There shouldn’t be any /tramping/ in the address. That is the folder name the tramping website is housed in.

It seems that somehow this is not affecting the other two websites. They are working perfectly. They were both set up a while ago and have never had an issue.

For a day after I added the https code I also had another line that I quickly removed:

RewriteCond %{HTTP_HOST} ^www.tramping.net.nz [NC]
RewriteRule ^(.*)$ https:/tramping.net.nz/$1 [L,R=301]

Any thoughts here as to how to remove the 404 issues.

I know that I should probably have had two // in that last line of code.

Should I add back that line to read: RewriteRule ^(.*)$ https://tramping.net.nz/$1 [L,R=301]

Man, for a non-coder I seem to be in very deep water here.

Then again, I may have answered my own question.

Offline

#2 2019-10-14 18:21:17

detail
Member
From: geez, I seem to be in NZ
Registered: 2010-07-13
Posts: 141
Website

Re: 404 woes with .htaccess coding

detail wrote #319695:

Should I add back that line to read: RewriteRule ^(.*)$ https://tramping.net.nz/$1 [L,R=301]

I added that line for an hour or so and the 404 rate went up to 50%.

Better without it.

Here’s a theory . . .

Seems that it may be coming from some hardcoded http://www. rather than https://

Offline

#3 2019-10-14 20:03:53

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 3,555
Website

Re: 404 woes with .htaccess coding

I’ll prefix this by saying I’m not an expert on this and I’m not sure I’ve totally understood your setup, but I would have thought that if each site is separate, you set your host to point each domain to its respective base folder and that each site has its own separate .htaccess file, so I’m not sure why you’d need a redirect that names all three domains explicitly. Maybe that has something to do with you particular setup?

I’ve found that the html5boilerplate offers some sound advice on what to set in .htaccess files and when. The salient parts for you could be:

The first of those should redirect incoming http:// links to https:// regardless of whether hard-coded somewhere in another link.

Note: The !^/\.well-known/… conditionals (!^… mean “but not beginning with…”) are sometimes needed if your certificate validation code needs to access a directory via regular http: when renewing. You may have received some instructions concerning that from your host if you purchased an SSL certificate.


TXP Builders – finely-crafted code, design and txp

Offline

#4 2019-10-21 11:02:38

detail
Member
From: geez, I seem to be in NZ
Registered: 2010-07-13
Posts: 141
Website

Re: 404 woes with .htaccess coding

It’s taken a while to get back to you Jakob, but that info was very useful.

Thanks very much for your interest.

I finally worked out why I was getting the 404s.

It was all hardcoded http//:www. that should have been just https//:

This six-year-old website is complicated by having 14 sections, and each section has a separate js slideshow. That meant when I originally set it up I found it easier to have a separate page for each section. Other than a similar slideshow and the menu, each section can have a reasonably different structure. One of the sections now has about 500 individual articles.

That overall structure, while inelegant, has actually worked well, just now painful to have some hardcoded addresses that are buried deep. I think I’ve found most of them. I know where to look for them now.

jakob wrote #319714:

I’m not sure why you’d need a redirect that names all three domains explicitly.

I have one .htaccess file for all 8 websites I host. It works. Only the three mentioned are https.

Offline

#5 2019-10-21 11:34:57

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,787
Website

Re: 404 woes with .htaccess coding

detail wrote #319794:

I know where to look for them now.

*cough* smd_where_used *cough* ;)

(although it needs updating for 4.7.3 as it falls apart with multiple themes right now)


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

#6 2019-10-21 12:14:35

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 3,555
Website

Re: 404 woes with .htaccess coding

Glad you got it working :-)

detail wrote #319794:

It was all hardcoded http//:www. that should have been just https//:

Some general pointers on that, in case it helps you or anyone else reading this thread.

If you use txp:site_url, txp:permlink or the built-in link="1" attribute (with the corresponding tags), you can then add this line to your config.php:

define('PROTOCOL', 'https://');

and from that moment on, Textpattern uses https:// for the internal site links.

Alternatively, you can construct your links without the domain name, e.g. /<txp:section />/<txp:article_url_title /> (with the preceding slash) for your internal page links, and the browser will use whatever protocol (http or https) is currently being used.

Note: You still need to check with links to other sites or when sourcing files from other sites like scripts or fonts etc.


TXP Builders – finely-crafted code, design and txp

Offline

Board footer

Powered by FluxBB