Textpattern CMS support forum

You are not logged in. Register | Login | Help

#21 2015-02-25 18:08:05

maniqui
Moderator
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: Image name instead ID in html

You are welcome, uli. :)

I’ll expand this tip, to explain how to craft this SEO/human-friendly URLs, so to take advantage of this .htaccess trick.

It basically involves using tags like txp:image_info to output the small pieces of information to craft the proper URL.
For example:

<txp:images>
  <img src="/images/<txp:image_info type="id" />/<txp:image_info type="name" /><txp:image_info type="ext" />
</txp:images>

Or, if you are using something like the smd_gallery plugin, that would be:

<txp:smd_gallery>
   <img src="/images/{id}/{name}{ext}" />
</txp:smd_gallery>

As you can see, we use the name of the image (editable for each image via Admin > Content > Images) as the source of the SEO/human-friendly string.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#22 2015-09-23 05:55:00

Pyanepsion
New Member
From: Clermont-Ferrand
Registered: 2015-09-22
Posts: 7
Website

Re: Image name instead ID in html

Rewriting is not a good solution. It is as if suddenly your faucet dripped a somewhat muddy trickle and you thought fix the thing by increasing the pressure of the water tower upstream and use filters and disinfectants downstream. Water will be certainly more fit for consumption, but it would have been better to simply repair the leak.

Here, the leak is the coding that replaces the image name with a number. So it is here it will act.


Mais je vous le demande : peut-on encore parler de police sans sérifs ?

Offline

#23 2015-09-23 17:13:25

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

Re: Image name instead ID in html

Pyanepsion, you may be right, but for better or worse the decision to use a number-based naming scheme was taken in the very early days of textpattern before most of us were around. Changing it would require modifications at all levels – in the file system, the admin system, the way of attaching images to an article as well as the image output tags … not to mention the problem of maintaining backwards compatibility…

The one advantage that using an image number has is that the image name can be changed at a later date without breaking existing links. The rewriting method maniqui describes is really only a cosmetic addition as the name part is irrelevant for the rewrite: only the id and ext are used. The name part can be anything, so you can tailor it to your own SEO needs.


TXP Builders – finely-crafted code, design and txp

Offline

#24 2015-09-24 21:07:59

qrayg
Member
From: USA
Registered: 2004-08-27
Posts: 81
Website

Re: Image name instead ID in html

This whole thread is exactly why on my dozen or so well trafficked TXP sites, I do not use or allow the customer to use the Image library. Maintaining these sites after years of customer use and hundreds of number-based image file names would make my life far more complicated than it needs to be. Allowing FTP access to an image folder is far simpler and allows for greater control IMO.

I love TXP, but this is the reason why it’s hard to sell to other developers and customers that want a decent media library solution in their CMS.

I understand it would be a massive change to make the images retain their name on upload and still allow every other aspect of the CMS to work without a hitch, but there has to be another way.

Umbraco uses that number id as a folder rather than renaming the image. Could that possibly be a solution or a path to solution that could work with TXP? I’m ok with that ID being part of the path to the image, I just don’t want TXP renaming my already organized naming scope.

Offline

#25 2015-09-25 08:25:05

Pyanepsion
New Member
From: Clermont-Ferrand
Registered: 2015-09-22
Posts: 7
Website

Re: Image name instead ID in html

The big CMS always know, at one time or another, major changes to correct errors of the initial codage.

By example, Wordpress has seen a major change in his script with version 3. We must also understand that the more time passes, more it becomes complicated to fix bugs departure. The mismanagement images is one. This update dish will probably not without difficulty and will require perhaps, as sometimes sees a conversion routine of the old system to the new.

This is a very important point that I think should become a priority to achieve during the next release.

It is unthinkable today that the URL of an image on a page, a script, and more generally a file to be reinterpreted by the script without our consent :
— If one wants to write for an image “/photo/my-image.png”, it must not become “http://example.com/photo/my-image.png” or worse “http://example.com/ image /1873 / my-image.png “or really worse” http://example.com/ image/1873.png “.
— If one wants to write for a CSS “style/screen.css”, it must not become “http://example.com/css.php?n=default”, etc.

This is all the more important that it can make the difference in SEO with some American, Chinese, or Russian search engines.


Mais je vous le demande : peut-on encore parler de police sans sérifs ?

Offline

#26 2015-09-25 12:11:18

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 7,344
Website

Re: Image name instead ID in html

The problem, as mentioned a number of times here, is duplicate image names. How do you propose to solve it? There are sites with thousands of images which makes name duplication possible. Also there are non web savvy users who use spaces or special (or restricted) characters for their images.

The txp method might not be the most SEO friendly but I find it to be the safest if we want to attract the average Joe who just want to either create or just update their website easily.

As always I am not absolute re this matter but I also think that it is not something that it can’t be ‘solved’ hastily. Food for thought.


Yiannis
——————————
neme.org | hblack.net | LABS | State Machines | Respbublika! | NeMe @ github

Offline

#27 2015-09-25 13:15:57

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

Re: Image name instead ID in html

You’re absolutely right in that the longer one waits, the more difficult it becomes to change. I wasn’t necessarily defending the numbering scheme used by txp, just noting that it’s not a simple fix and not without repercussions. Whether its mismanagement or just a different management approach is debatable.

If you want to achieve full-text image names in your source code at this point in time, the rewriting scheme discussed in this thread is one possible solution. In addition, it is one you could expand to accommodate language-specific seo requirements: just adjust the htaccess rewriting scheme and adapt your image names accordingly.

For the record, there’s nothing stopping you using folders and flat files, they just won’t be managed through txp. The disadvantage is you can’t then use the various image output and organisation tags.

The css is more straightforward: you can use an /assets/styles/screen.css-type setup and simply link to them directly from your template. If you don’t want to lose the ability to use the presentation tab to edit them (I personally prefer to use a code editor), you can also use rvm_css to maintain flat file css through the admin area.


TXP Builders – finely-crafted code, design and txp

Offline

#28 2016-04-18 09:55:59

NicolasGraph
Plugin Author
From: France
Registered: 2008-07-24
Posts: 860
Website

Re: Image name instead ID in html

maniqui wrote #288593:

Hi all,
I’ve rewritten the regex a bit, to have just one rule to rule them all. :P
Test and report back :)

See also the other half for this trick (on how to implement SEO/human-friendly URLs for images).

Thanks Julián; unfortunatly the regex didn’t work for me but the following is ok RewriteRule ^(.+[/])?([0-9]+t?)(?:[-/]).+(png|gif|je?pg|bmp|webp)$ $1$2.$3 [NC,L] (I don’t use smd_thumbnail).

Edit: for ovh hosting some .htaccess changes are needed

Last edited by NicolasGraph (2016-10-05 13:40:33)


Nicolas
Follow me on Twitter and GitHub!
Multiple edits are usually to correct my frenglish…

Offline

#29 2018-05-17 06:48:34

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 7,344
Website

Re: Image name instead ID in html

After watching this TED talk on how google reads images for its search results, I am bringing back this thread with an idea. What if the image names were using the site name as a prefix? ie something like site_name_134.jpg. If we used this method, the images would be site branded.

> Edit: Scrap that as it will make changing of domain names a real nightmare!

Last edited by colak (2018-05-17 12:28:00)


Yiannis
——————————
neme.org | hblack.net | LABS | State Machines | Respbublika! | NeMe @ github

Offline

#30 2018-05-18 09:21:59

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

Re: Image name instead ID in html

colak wrote #311861:

Scrap that as it will make changing of domain names a real nightmare!

I was wondering that! Very thoughtful talk though, as it shows the fragility of search results from a moral standpoint. Thanks for sharing.


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

Board footer

Powered by FluxBB