Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2016-01-04 17:35:24

Registered: 2005-09-10
Posts: 289

Clean URL Queries?

Is it possible to allow clean query/variables in urls?

I’d like images in an article gallery to have separate permlinks — something like ihis:


The first part of the url is the normal permlink (as defined in txp preferences):

In this example, “24” would be the image id and the image-title-alt would be the alt text of the image.

Wordpress has a function that allows for this type of thing. Is it possible with Textpattern?


#2 2016-01-05 11:15:40

From: Germany
Registered: 2005-01-20
Posts: 3,969

Re: Clean URL Queries?

You can use the plugin gbp_permanent_links to create your url schemes but it requires a little experimentation and is, unfortunately, not well documented. That would be a tcp-internal way of doing it.

Alternatively, you could achieve that with a rewrite rule in your .htaccess file. Something like this within your RewriteEngine On section:

RewriteRule ^([^/]+)/([^/]+)/image/(\d+)/(.+)$ /$1/$2?img-id=$3&img-alt=$4

And then use adi_gps to retrieve img-id and img-alt (if you need it at all) as txp variables for use in your page template…

TXP Builders – finely-crafted code, design and txp


#3 2016-01-08 12:45:55

Plugin Author
From: Germany/Ukraine
Registered: 2007-10-08
Posts: 272

Re: Clean URL Queries?

I realize something in this direction with a special form.
<txp:images id="678" form="images_thumb" />
and the form looks like that:

<a href='<txp:site_url /><txp:image_info type="name" />/<txp:image_info type="id" />/' target="_blank" rel="lightbox" title='Picture: <txp:image_info type="caption" />'><img class="nofloat" title='<txp:image_info type="caption" />' alt='<txp:image_info type="alt" />' 
src='<txp:site_url /><txp:image_info type="name" />/<txp:image_info type="id" />t/' /></a>

the url is rewritten by the webserver. In my case Lighttpd.
"^/.[^/]+\.(png|gif|jpe?g|bmp)/([0-9]+t?)/$" => "/images/$2.$1"

for Apache it should look like that:
RewriteRule "^/.[^/]+\.(png|gif|jpe?g|bmp)/([0-9]+t?)/$" "/images/$2.$1" [L]

the URL looks in the end like that and I identify the image by the number.


#4 2020-10-26 22:10:11

Registered: 2005-09-10
Posts: 289

Re: Clean URL Queries?

Long time, no see! I’m finally getting around to bringing my site up to date from TXP 4.5.7 (with PHP 5.6) to TXP 4.8.3 (with PHP 7.3). Things are going well. I’ve upgraded plugins, etc. However, I’m stuck on a clean URL scheme that had been working with adi_gps since I implemented it back in 2016. Here’s a link to the problem (click on any thumbnail and it will take you to my 404 error page: https://www.staceyirvin.com/truck-stop

The following was in my .htaccess file just after RewriteEngine On and worked on my TXP 4.5.7 site (the <txp:adi_gps /> tag at very top of the page template):

RewriteCond %{HTTP_HOST} !^www.staceyirvin.com$ [NC]
RewriteRule ^(.*)$ https://www.staceyirvin.com/$1 [L,R=301]
RewriteRule ^([^/]+)/image/(\d+)/(.+)$ /$1?image=$2&img-alt=$3

Below is my current .htaccess file – the clean urls with image id and img alt aren’t working correctly:

# BEGIN Textpattern

#DirectoryIndex index.php index.html

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{HTTPS} off 
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

    RewriteCond %{HTTP_HOST} !^www.staceyirvin.com$ [NC]
    RewriteRule ^(.*)$ https://www.staceyirvin.com/$1 [L,R=301]
    RewriteRule ^([^/]+)/image/(\d+)/(.+)$ /$1?image=$2&img-alt=$3

    # Enable the `FollowSymLinks` option below if it isn't already.
    #Options +FollowSymlinks

    #RewriteBase /relative/web/path/

    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^(.+) - [PT,L]

    RewriteCond %{REQUEST_URI} !=/favicon.ico
    RewriteRule ^(.*) index.php

    RewriteCond %{HTTP:Authorization}  !^$
    RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization}]

<IfModule mod_mime.c>
    AddType image/svg+xml  svg svgz
    AddEncoding gzip       svgz

# For additional Apache-compatible web server configuration settings to enhance
# site performance and security, we recommend:
# https://github.com/h5bp/server-configs-apache/blob/master/dist/.htaccess

# END Textpattern

Any thoughts on what I’m missing? Thanks in advance!

Last edited by photonomad (2020-10-26 22:12:55)


Board footer

Powered by FluxBB