Please login or register.

Login with username, password and session length
Advanced search  

News:

Latest sNews - sNews 1.7 - with its own forums - for discussion and user mods.

Author Topic: Rewritten URLs do not handle directories consistently  (Read 5600 times)

reactionengine

  • Newbie
  • *
  • Karma: 0
  • Posts: 4
Rewritten URLs do not handle directories consistently
« on: May 04, 2008, 11:31:22 PM »

I just installed the current stable snews, and it appears that while the mod_rewrite rules create a directory structure, it is not consistent. So

/category is 200 OK and so is /category/
/category/article is 200 OK and so is /category/article/

The following additional rules permanently (301) redirect /category to /category/ and /category/article/ to category/article

My preference is for a trailing slash to only appear on directories that contain more than one resource. Hence the omission of both file extension and trailing lash on individual article pages.

I don't know if this issue has already been dealt with, however this was my implementation. You may need different rules if snews is installed in a root directory (mine was in /snews/ as exemplified below). These rules should appear before the other rewrites.

Code: [Select]
# include the path to snews to avoid path translation(?) problems
RewriteBase /snews

# trailing slash fix

# /category = /category/
RewriteRule ^([a-z_-]+)$ $1/ [R=301,L]

# /category/article/ = /category/article - switch the slash if you want meaningless directories like /category/article/
RewriteRule ^([a-z_-]+)/([a-z_-]+)/$ $1/$2 [R=301,L]
Logged

Joost

  • Guest
Re: Rewritten URLs do not handle directories consistently
« Reply #1 on: May 05, 2008, 01:48:33 AM »

Welcome to sNews reactionengine,

Since this is working for me, I guess the fullcode would look something like:

Code: [Select]
RewriteEngine On
#RewriteBase /sNews

RewriteRule ^([a-z_-]+)$ $1/ [R=301,L]
RewriteRule ^([a-z_-]+)/([a-z_-]+)/$ $1/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.+) $1 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+) index.php?category=$1 [L]

Internally, the uri would look like index.php?category=/category/, processed by sNews as $(GET['category']
In what way will sNews profit from the new rewrite rules?
Logged

reactionengine

  • Newbie
  • *
  • Karma: 0
  • Posts: 4
Re: Rewritten URLs do not handle directories consistently
« Reply #2 on: May 05, 2008, 05:03:15 PM »

It may seem finnicky, however I believe conventions are there for a reason, and often conventions of this sort are learned by users and impact usability.

Directories require a trailing slash; while sNews is not actually creating filesystem directories, it is simulating this structure for users, so I believe consistency is beneficial. Similarly, individual files should not be proceeded by a trailing slash, and so I see no reason for them to be included.

From a usability standpoint, a directory carries the implication that it contains more than once resource, so /category/ seems appropriate. Filenames are a standalone resource and so a trailing slash is superfluous and hence /category/article seems the best choice. Users can then get meaningful information merely by looking at a URL. As I understand it, there are no subcategories within snews (could be wrong here though as I'm just testing it at the moment) however it would be easy to see that /category/subcategory invites confusion, whereas /category/subcategory/ does not.

Incidentally, a better pattern would likely be [0-9a-z_-]+ since I didn't account for either category or article names containing numbers.
Logged

Joost

  • Guest
Re: Rewritten URLs do not handle directories consistently
« Reply #3 on: May 05, 2008, 06:45:15 PM »

First of all 1.7 rc has got subcategories. That's where it is heading.
Most users don't even notice domainnames, why would they be confused by slashes, that shouldn't be there according to some convention? If that was true, no one would be able to browse this forum.
In my opinion usability is about pages, menus on pages and clear site structures. The only time when I mess with uris, is when I land upon a page, that does not provide a clear menu that brings me to the root or a higher level.
Logged

reactionengine

  • Newbie
  • *
  • Karma: 0
  • Posts: 4
Re: Rewritten URLs do not handle directories consistently
« Reply #4 on: May 05, 2008, 08:28:22 PM »

Quote
usability is about pages, menus on pages and clear site structures

That's a rather limited view of usability. But in any case, clear site structure should be reflected by best practice URLs. As I said, it may seem finnicky, but I am particular about such things. Why make categories look like directories if they don't behave like them? Even aside from that, why break the one URI per document model?

Quote
If that was true, no one would be able to browse this forum.

Frankly, that's a disingenuous argument. I never claimed that this was a major usability problem, and even pointed out that I was being finnicky.

I'm of the opinion that just because a slash is only a small character that doesn't mean that tidiness and best practice does not apply. The makers of Apache, IIS and even Tim Berners-Lee all seem to agree with their own implementations and recommendations.

Less important, but still relevant, is that unintenional duplicates are known to cause problems with search engines' interpretation of canonical URLs, and yes, this can apply even with a forward slash. I mention this as search engine friendliness (and URLs in particular) is listed on the homepage of the site, rather than because this is my favoured reason to fix slashes.

A simple Google search shows that I am not alone in giving due consideration to trailing slashes when creating URLs
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Re: Rewritten URLs do not handle directories consistently
« Reply #5 on: May 05, 2008, 10:34:17 PM »

@Reactionengine... no need to react or debate the issue... feel free to do what suits you... that's the kind of freedom we foster here at sNews.
You take any package and.or mods you like... do what you want (or don't want) with 'em and so on.
Personally, I don't care for the extra slash at the end of URLs either but... at the same time... I'm not 'finnicky' about them. Interestingly... none of my clients have noticed or questioned them either. So all of my sNews-powered site projects have URLs with slashes on the end.
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

reactionengine

  • Newbie
  • *
  • Karma: 0
  • Posts: 4
Re: Rewritten URLs do not handle directories consistently
« Reply #6 on: May 06, 2008, 12:08:57 AM »

Fair enough Keyrocks - although personal preference is not really the reason I posted - it's the fact that sNews doesn't choose one way or the other :P
Logged

Joost

  • Guest
Re: Rewritten URLs do not handle directories consistently
« Reply #7 on: May 06, 2008, 02:15:32 AM »

Not meant to be a disingenuous argument, reactionengine. Just to emphasize that I see no usability issue, major or minor.
In your search, I did not find any documentation saying pages should not have a trailing slash. However, there might be an issue when a slash is forgotten.
Logged