Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2005-07-24 19:40:46

jiraiya
Member
Registered: 2005-05-15
Posts: 13

Request: URL trailing slash plugin

When using clean URLs, all the URLs does not end with a trailing slash.

For example:

“www.example.com/section/clean-url”

The correct URL should be:

“www.example.com/section/clean-url/”

The reason the slash is important is because all search engines sees these as two different urls which can cause undesirable duplicates and inconsistencies. It also adds extra load for the server to check if it is a directory or not.

There is a fix for Wordpress for the same issue. http://scott.yang.id.au/2005/05/permalink-redirect/

I wanted to put this problem out there so hopefully someone might be able to create a plugin to fix the trailing slash problem. :) Maybe it’s possible to port the Wordpress plugin to Textpattern.

Last edited by jiraiya (2005-07-24 19:41:47)

Offline

#2 2005-07-24 20:13:24

sekhu
Member
Registered: 2005-05-12
Posts: 428
Website

Re: Request: URL trailing slash plugin

This is news to me – will be interesting to hear feedback on whether this is simply a herring

Offline

#3 2005-07-24 20:14:54

andreas
Member
Registered: 2004-02-28
Posts: 453
Website

Re: Request: URL trailing slash plugin

The plugins zem_rewrite, mic_permlink and sgb_url_handler allow to add a trailing slash if you want.

Offline

#4 2005-07-24 20:28:47

ubernostrum
Member
From: Lawrence, KS
Registered: 2004-05-05
Posts: 238
Website

Re: Request: URL trailing slash plugin

Search engines aren’t a problem so long as you decide whether to use trailing slashes or not, and then do so consistently. It’s only if you refer to the same content with a trailing slash in one place and without in another that search engines will be bothered.

I would imagine that the alleged server load increase is also moot, given that the server never gets that far (e.g., if your permalink is /weblog/2005/07/clean-url, the server’s going to stop investigating the path when it sees there’s no directory called ‘weblog’, and hand off to mod_rewrite).


You cooin’ with my bird?

Offline

#5 2005-07-24 22:59:40

michaelkpate
Moderator
From: Avon Park, FL
Registered: 2004-02-24
Posts: 1,379
Website GitHub Mastodon

Re: Request: URL trailing slash plugin

Personally, I like to think of them as entirely non-crufty URIs. I have never understood the propensity of WordPress to refer to directories when an individual file would do.

That being said, I would like to be able to use Scott’s plugin in Textpattern. Only I would like to be able to rewrite the request to not include the slash.

Offline

#6 2006-01-19 20:20:23

lunaport
Member
From: Chicago, IL
Registered: 2004-03-03
Posts: 13
Website

Re: Request: URL trailing slash plugin

I’ll take a look at the plug-ins mentioned above. But, if it were up to me, Textpattern would add a trailing slash natively (perhaps via a preference setting). Why? I think it’s cleaner-looking, it’s consistent with the URL structure on other parts of my sites that are not content-managed by Textpattern, it’s future-proof in the event that I stop using TP but want to mimic the same directory structure; there are lots of good reasons. Someone even wrote an article: Slash Forward.

Last edited by lunaport (2006-01-19 20:21:37)

Offline

#7 2006-01-19 22:06:19

Sencer
Archived Developer
From: cgn, de
Registered: 2004-03-23
Posts: 1,803
Website

Re: Request: URL trailing slash plugin

The reason the slash is important is because all search engines sees these as two different urls which can cause undesirable duplicates and inconsistencies.

You almost got it correct. You explain why it is important to be consistent with the urls used, not why a slash would be necessary.

Textpattern is very consistent with urls, so there are not troubles with search engines.

It also adds extra load for the server to check if it is a directory or not.

No, Textpattern doesn’t create files or directories, it works with a database. So this doesn’t come into play. (Little hint: Even it it did apply to this situation – which it doesn’t – the time spent for doing this is lost in noise if you try to measure it; those microseconds are just not relevant.)

I think it’s cleaner-looking,

I think the opposite is the case – adding characters to the url that serve no purpose uglify urls, IMHO.

it’s consistent with the URL structure on other parts of my sites that are not content-managed by Textpattern,

Now that’s a good reason. I would agree that a pugin is the best to handle this for you.

it’s future-proof in the event that I stop using TP but want to mimic the same directory structure

Having a slash at the end or not, doesn’t affect this. (You can have a directory and a file with the same name without a problem.)

Someone even wrote an article: Slash Forward.

The article talks about a different thing: it deals with actual (file-system) directories. In our case it’s all virtual anyhow.
They are talking about decoupling the URIs from the technology => Textpattern already does this. They imply that hiding file extensions is good for security – while I disagree, Textpattern also does this (but for other reasons).

I don’t see anything in that article that supports the argument that Textpattern should add a slash to the urls.

Offline

#8 2006-01-20 13:26:31

lunaport
Member
From: Chicago, IL
Registered: 2004-03-03
Posts: 13
Website

Re: Request: URL trailing slash plugin

I think the opposite is the case – adding characters to the url that serve no purpose uglify urls, IMHO.

Right, it’s a matter of opinion, which is why I think it’s a good candidate for a preference. On second thought, it wouldn’t even require a new preference, just a new option in the “Permanent link mode” drop-down.

Having a slash at the end or not, doesn’t affect this. (You can have a directory and a file with the same name without a problem.)

Right, but then we’re back to inconsistency, at least during a transition period to or from TP. Will PageRank established with file-based TP carry over if a switch is made to a directory-based system?

I don’t see anything in that article that supports the argument that Textpattern should add a slash to the urls.

Right, but it does give several valid reasons why a TP user might want to establish a consistent approach to URLs both site-wide and past/present/future.

This is not a show-stopper for me, so I’m done posting about it. I’ll take a look at the plug-ins. Thanks for all your hard work. Textpattern really is a gem.

Offline

#9 2006-01-23 01:54:27

Dawk
Member
Registered: 2005-02-22
Posts: 74

Re: Request: URL trailing slash plugin

I’m not concerned about the trailing slash, but choice is a good thing :)

I’d be more interested in the ability to add “.htm” to the end of articles & permlinks. (trailing slashes too in that case)

my 2 pesos

Offline

#10 2006-02-05 10:05:40

David_1cog
Member
From: Bristol, England
Registered: 2004-09-09
Posts: 58
Website

Re: Request: URL trailing slash plugin

Another vote here to provide trailing slash as an option. I haven’t started playing with the it yet, but isn’t this possible with just a tweak of the .htaccess?


David @ 1 Cog
“Follow the shoe!” … “No, follow the gourd!”

Offline

#11 2006-02-05 17:29:46

Andrew
Plugin Author
Registered: 2004-02-23
Posts: 730

Re: Request: URL trailing slash plugin

Try adding this to a form and include that form in the first line of your site’s header template. There are no guarantees that it’ll work in all instances, but it seems to work ok for me.

<txp:php>
$req = explode('?', $_SERVER['REQUEST_URI']);

// redirect to add a missing trailing slash (maintain querystring)
// do nothing if there's post vars
if (substr($req[0], -1, 1) != '/' && empty($_POST)) {
	$qs = ( 
		!empty($req[1])
			? '?' . $req[1]
			: ''
	);
	$loc = 'http://'.$_SERVER['HTTP_HOST']."{$req[0]}/$qs";
	txp_status_header('301 Moved Permanently');
	header("Location: $loc");
}
</txp:php>

If you find this useful and bug-free, I’ll turn it into a plugin for ya.

Last edited by Andrew (2006-02-05 19:09:55)

Offline

#12 2006-02-05 17:39:31

Andrew
Plugin Author
Registered: 2004-02-23
Posts: 730

Re: Request: URL trailing slash plugin

Oh, keep in mind that it’s not first checking to see if the url you’re requesting is an existing article, so if an invalid url is requested that lacks trailing slash you’re going to get a 301 followed by a 404. Which is worse, duplicate urls or 301->404?

Offline

Board footer

Powered by FluxBB