Obligatory trailing slashes on 'name based' permalinks: Add redirect
-
Hello,
Currently, the name-based forum permalinks must have a trailing ‘/’ – this is fair enough, but it gets seriously bad when one is typing in forum URLs and forgets the trailing ‘/’, only to be slapped down with an unhelpful 404 error. Ouch.
I modified the .htaccess, moving the section commented ‘forums’ down under the ‘topics’ section (so the catch-some rewrite rule I added doesn’t wipe that out), then added a rule that redirects URLs that address a path within the forum root, sans a trailing slash and not corresponding to an actual file, to the same path with a trailing ‘/’.
Like so:
# forums
RewriteRule ^([^/]+)/page/([0-9]+)/?$ forum.php?id=$1&page=$2 [L,QSA]
RewriteRule ^([^/]+)/$ forum.php?id=$1 [L,QSA] # tailed '/' is mandatory for forum URIs! Props: Mohta
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ $1/ [L,R=301] # redirect to forum URL if trailing / skipped
I’m not 100% sure why this isn’t already in place – I may have missed some of the rationale. But it seems to work for me.
- You must be logged in to reply to this topic.