Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Re: smd_short_url: tiny/canonical URLs
THE BLUE DRAGON wrote:
when I try to go to http://www.domain.com/1213 it brings me to the error page.
You don’t need to do anything besides install and activate the plugin so it should just work. A few questions:
- Are you using v0.2 of the plugin?
- Are you using TXP 4.2.0?
- Do you have any gbp_permanent_links or htaccess rules that might be colliding with the plugin?
- Are you using any subdomains or multi-site capability?
- Are there any other plugins that might be getting in the way? (MLP for example)
Please let me know the answers to the above and we might be able to track this down.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline
Re: smd_short_url: tiny/canonical URLs
- Are you using v0.2 of the plugin?
- Are you using TXP 4.2.0?
- Do you have any gbp_permanent_links or htaccess rules that might be colliding with the plugin?
- Are you using any subdomains or multi-site capability?
- Are there any other plugins that might be getting in the way? (MLP for example)
yep v0.2
yep v4.2.0
no gbp_permanent_links or htaccess rules
any subdomains or multi-site capability? mmm…no but it is on Godaddy server if it makes any different
my plugins are: adi_calc | bot_privs | chh_if_data | ebl-image-edit | fpx_image_import | hcg_templates | ied_replacer | jbx_multiple_image_upload | rss_admin_show_adv_opts | rss_auto_excerpt | rss_suparchive | rvm_counter | smd_calendar | smd_countdown | smd_gallery | smd_if | smd_lib | smd_short_url | zem_contact_lang | zem_contact_reborn.
here some Diagnostic info:
Document root: /home/content/f/l/a/******/html
$path_to_site: /home/content/f/l/a/******/html
Textpattern path: /home/content/f/l/a/******/html/textpattern
Permanent link mode: section_title
Temporary directory path: /home/content/f/l/a/******/html/textpattern/tmp
MySQL: 4.1.22-max-log
Locale: en_GB.UTF-8
Server: Apache
PHP Server API: cgi-fcgi
RFC 2616 headers:
Server OS: Linux 2.4.21-53.ELsmp
.htaccess file contents:
————————————
#DirectoryIndex index.php index.html
#Options +FollowSymLinks
#Options -Indexes
<IfModule mod_rewrite.c> RewriteEngine On #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>
#php_value register_globals 0
Offline
Re: smd_short_url: tiny/canonical URLs
THE BLUE DRAGON
Thanks for the detailed diag. Weird: can’t see any reason for it to fail. The plugin works fine on my dev site, though it doesn’t work on my actual stefdawson.com domain — but that’s probably because I have a truckload of custom .htaccess rules. In your case, you’re using a stock .htaccess so it’s not that.
Nothing jumps out at me in your plugin list (btw, rss_admin_show_adv_opts is probably not needed any more) so I really don’t know why it would be giving you a 404. I assume you do have an article ID = 1213?! (that’s a lot of articles…)
Could you please modify the plugin and let me know what you see (mail it to me if you don’t want to reveal the site location here). I’ll think about making debug a bit easier in a future version.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline
Re: smd_short_url: tiny/canonical URLs
1. I did modify the plugin, and no change it gives me an HTTP 404 Not Found error
2. Thanks deleted rss_admin_show_adv_opts ;)
3. No I don’t have an article id#1213, it was just en example but I do have an article id#810
Offline
Re: smd_short_url: tiny/canonical URLs
THE BLUE DRAGON wrote:
I did modify the plugin, and no change it gives me an HTTP 404 Not Found error
Ooops, I forgot to add an important line: you need the exit; or you won’t see the output when it redirects! I’ve updated the post above to reflect this. Please try again, sorry.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline
Re: smd_short_url: tiny/canonical URLs
OK I added the exit; but still no any change at all
O_o
Offline
Re: smd_short_url: tiny/canonical URLs
THE BLUE DRAGON wrote:
OK I added the
exit;but still no any change at all
Bizarre. It’s definitely running the plugin OK because you can see the diag output (thanks for the site link).
OK, another test. Please alter the plugin again to get rid of all the dmp and exit; lines we’ve added, then change it so it reads:
$have_id = preg_match($re, $_SERVER['REQUEST_URI'], $m);
if ($have_id) {
$id = $m[1];
$permlink = permlinkurl_id($id);
dmp($permlink);
exit;
That should display the permlink of the article it is trying to redirect to. If that matches the url-title of the article you are expecting, then something is definitely getting in the way somewhere because immediately after that the plugin does the redirect.
Last edited by Bloke (2009-09-15 08:21:59)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline
Re: smd_short_url: tiny/canonical URLs
mmm…sorry still not working here is the change
register_callback('smd_short_url', 'txp_die', 404);
function smd_short_url($event, $step) {
$urlparts = parse_url(hu);
$re = '#^'.$urlparts['path'].'([0-9].*)#';
$have_id = preg_match($re, $_SERVER['REQUEST_URI'], $m);
if ($have_id) {
$id = $m[1];
$permlink = permlinkurl_id($id);
dmp($permlink);
exit;
if ($permlink) {
ob_end_clean();
header("HTTP/1.0 301 Moved Permanently");
header("Location: $permlink");
die();
}
}
}
function smd_canonical($atts, $thing='') {
global $pretext;
extract(lAtts(array(
'type' => 'link',
), $atts));
assert_article();
$link = hu.$pretext['id'];
$out = '';
if ($type=="link") {
$out = '<link rev="canonical" href="'.$link.'" />';
} else {
$out = $link;
}
return $out;
}
Offline
Re: smd_short_url: tiny/canonical URLs
THE BLUE DRAGON wrote:
mmm…sorry still not working
Well it won’t “work” as such with the exit; in it because the plugin then stops the rest of the site rendering! But when I visit your ‘domain.com/number’ page (do a forced CTRL-F5 refresh) I see the correct URL it is trying to forward to.
In other words, the plugin has translated the /number into a real article URL. The next thing it does is simply forward you there using the header() function. Thus, as far as the plugin is concerned it is doing its job properly. After that, other cosmic forces are getting in the way (cache?) to show you the 404 instead of what you expect to see.
Have you any custom error_default or error_404 Pages set up? I’m not sure if that will make any difference because I can’t remember when they’re called in the order of page execution, but since we’ve ruled out htaccess, it might have a bearing on things.
P.S. you can take out the dmp() and exit; calls once you’ve looked at the URLs it has generated, since I’m happy the plugin is doing its job ok, as far as it can.
Last edited by Bloke (2009-09-15 08:53:14)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline
Re: smd_short_url: tiny/canonical URLs
v0.21 is posted thanks to The Blue Dragon letting me diagnose this one. It appears that under some circumstances (as yet undetermined) the header() function is just ignored. Until I can find out why I’ve issued 0.21 as a kludgefix which simply does some extra header setting to keep IE happy and then falls back on a stupid HTML redirect in the event the header method fails.
If anyone knows why header() fails sometimes and is simply skipped over, please feel free to enlighten me. Ta!
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline
Re: smd_short_url: tiny/canonical URLs
Bloke wrote:
If anyone knows why header() fails sometimes and is simply skipped over, please feel free to enlighten me. Ta!
- From URL perspective, if there is encoded special chars. But as it is non-messy url, there shouldn’t be anything to encode. Altho
permlinkurl_id()outputs encoded URLs. - Fcgi +
ob_+ redirect +/- space somewhere + trying to reset the status. ob_end_clean()/ob_start()problems.
Um, does it work if you directly redirect w/o ob_end_clean()?
Offline
Re: smd_short_url: tiny/canonical URLs
Gocom wrote:
if there is encoded special chars…
permlinkurl_id()outputs encoded URLs.
Didn’t know that; worth knowing thanks. In this case it wasn’t that, but it might be that in future on someone else’s system.
Fcgi +
ob_+ redirect +/- space somewhere + trying to reset the status.
Could be. What confused me was that it worked on my dev site but not on my live stefdawson.com site; both on the same server. Thus I think it’s something in the way TXP is set up that’s triggering it to work or not. On my live site it may be the tonne of .htacess rules so I can’t really test it properly there.
does it work if you directly redirect w/o
ob_end_clean()?
Nope. I tried that :-( Even tried hard-coding it like this with nothing else in the plugin:
header("Location: http://site.com/articles/article-name");
and no dice. Freaky. I tried flushing the buffer afterwards as well. I totally don’t get it…
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline
#28 2009-11-04 09:08:00
- brendstrup
- Member

- From: Århus, Denmark
- Registered: 2007-05-05
- Posts: 15
Re: smd_short_url: tiny/canonical URLs
This is a great plugin! One small request:
Is there any way to easily make it generate www-free URLs? I’d like to continue using www.domain.com for the actual site, but to generate the shortest short-URLs possible, I’d like to use only domain.com for that. I already have the server setup to redirect to www, so that should work fine.
Offline
Offline
#30 2009-11-04 14:36:36
- brendstrup
- Member

- From: Århus, Denmark
- Registered: 2007-05-05
- Posts: 15
Re: smd_short_url: tiny/canonical URLs
Gocom wrote:
You can just simply link to
example.com/article-id.
I have tried that, but it doesn’t work, oddly enough. I think it might be a problem with the site’s .htaccess rules. I just discovered that if I edit an url like www.domain.com/section/page to domain.com/section/page (i.e. remove the subdomain), the page that loads is www.domain.com/index.php/page, which gives an error.
This isn’t a Textpattern error that any of you know about, is it? I assume it’s local .htaccess trouble, in which case I’ll have to tinker a bit.
Edit 10.11.20009: I fixed the .htaccess-problems and now I can indeed just link to example.com/article-id. Thanks for the help!
Last edited by brendstrup (2009-11-10 12:57:30)
Offline