Page 1 of 1
.htaccess rewrite rule to remove trailing slash
Posted: Mon Nov 06, 2006 3:14 pm
by docbrown
Hi!
I'm still searching for a solution to let serendipity get rid of trailing slashes in incoming urls. Is it better to handle it with .htaccess (if yes how?) or to edit index.php and the url rewriting?
Re: .htaccess rewrite rule to remove trailing slash
Posted: Tue Nov 07, 2006 10:07 am
by garvinhicking
Hi!
Where exactly, in which permalink do you want to remove a trailing slash?
Trailing slashes are actually better both in terms of HTTP lookups and in terms of SEO/Google.
Best regards,
Garvin
Posted: Tue Nov 07, 2006 6:40 pm
by docbrown
Okay, but: I have a problem with old and existing links to my page. A few month ago, i made an "upgrade" from wordpress to serendipity. Wordpress was using links with a trailing slash at the end. Thats why, differnt pages know my links with that slash. I was just trying to handly that small problem. How to teach serendipity to accept links (means show the articles) with and without a trailing slash...
Posted: Tue Nov 07, 2006 7:34 pm
by garvinhicking
Hi!
If you remove the %id% from permalinks, you have little options to accept the permalink, because s9y will match only the full link against the 'serendipity_permalinks' DB table. You would need to patch serendipity to always insert two entries into that DB table: One with slash, and one without.
If you howeve rkeep the %id% value in your permalink, you can simply edit your .htaccess file to replace "/" with "/?" in the permalink regex.
The other option you have is to generally use mod_rewrite to redirect all your trailing slash URLs with no-traling-slash URLs. If you can give us your precise .htaccess content, I can have a try at modifying that for you.
Regards,
GArvin
Posted: Wed Nov 08, 2006 6:14 pm
by docbrown
garvinhicking wrote:If you howeve rkeep the %id% value in your permalink, you can simply edit your .htaccess file to replace "/" with "/?" in the permalink regex.
The other option you have is to generally use mod_rewrite to redirect all your trailing slash URLs with no-traling-slash URLs. If you can give us your precise .htaccess content, I can have a try at modifying that for you.
That would be great. Here it is.
Code: Select all
# BEGIN s9y
ErrorDocument 404 /index.php
DirectoryIndex /index.php
RewriteEngine On
RewriteBase /
RewriteRule ^([0-9]{4}/[0-9]{1,2}/[0-9]{1,2}/[0-9a-z\.\_!;,\+\-]+) index.php?/$1 [NC,L,QSA]
RewriteRule ^(authors/([0-9]+)-[0-9a-z\.\_!;,\+\-]+) index.php?/$1 [NC,L,QSA]
RewriteRule ^(feeds/categories/([0-9;]+)-[0-9a-z\.\_!;,\+\-]+\.rss) index.php?/$1 [NC,L,QSA]
RewriteRule ^(feeds/authors/([0-9]+)-[0-9a-z\.\_!;,\+\-]+\.rss) index.php?/$1 [NC,L,QSA]
RewriteRule ^(categories/([0-9;]+)-[0-9a-z\.\_!;,\+\-]+) index.php?/$1 [NC,L,QSA]
RewriteRule ^archives([/A-Za-z0-9]+)\.html index.php?url=/archives/$1.html [NC,L,QSA]
RewriteRule ^([0-9]+)[_\-][0-9a-z_\-]*\.html index.php?url=$1-article.html [L,NC,QSA]
RewriteRule ^feeds/(.*) index.php?url=/feeds/$1 [L,QSA]
RewriteRule ^unsubscribe/(.*)/([0-9]+) index.php?url=/unsubscribe/$1/$2 [L,QSA]
RewriteRule ^approve/(.*)/(.*)/([0-9]+) index.php?url=approve/$1/$2/$3 [L,QSA]
RewriteRule ^delete/(.*)/(.*)/([0-9]+) index.php?url=delete/$1/$2/$3 [L,QSA]
RewriteRule ^(admin|entries)(/.+)? index.php?url=admin/ [L,QSA]
RewriteRule ^archive/? index.php?url=/archive [L,QSA]
RewriteRule ^(index|atom[0-9]*|rss|b2rss|b2rdf).(rss|rdf|rss2|xml) rss.php?file=$1&ext=$2
RewriteRule ^(plugin|plugin)/(.*) index.php?url=$1/$2 [L,QSA]
RewriteRule ^search/(.*) index.php?url=/search/$1 [L,QSA]
RewriteRule ^(serendipity\.css|serendipity_admin\.css) index.php?url=/$1 [L,QSA]
RewriteRule ^index\.(html?|php.+) index.php?url=index.html [L,QSA]
RewriteRule ^htmlarea/(.*) htmlarea/$1 [L,QSA]
RewriteRule (.*\.html?) index.php?url=/$1 [L,QSA]
<Files *.tpl.php>
deny from all
</Files>
<Files *.tpl>
deny from all
</Files>
<Files *.sql>
deny from all
</Files>
<Files *.inc.php>
deny from all
</Files>
<Files *.db>
deny from all
</Files>
# END s9y
Posted: Wed Nov 08, 2006 7:51 pm
by garvinhicking
Hi!
Can you try if this works:
Code: Select all
# BEGIN s9y
ErrorDocument 404 /index.php
DirectoryIndex /index.php
RewriteEngine On
RewriteBase /
RewriteRule ^([0-9]{4}/[0-9]{1,2}/[0-9]{1,2}/[0-9a-z\.\_!;,\+\-]+)/? index.php?/$1 [NC,L,QSA]
RewriteRule ^(authors/([0-9]+)-[0-9a-z\.\_!;,\+\-]+)/? index.php?/$1 [NC,L,QSA]
RewriteRule ^(feeds/categories/([0-9;]+)-[0-9a-z\.\_!;,\+\-]+\.rss) index.php?/$1 [NC,L,QSA]
RewriteRule ^(feeds/authors/([0-9]+)-[0-9a-z\.\_!;,\+\-]+\.rss) index.php?/$1 [NC,L,QSA]
RewriteRule ^(categories/([0-9;]+)-[0-9a-z\.\_!;,\+\-]+)/? index.php?/$1 [NC,L,QSA]
RewriteRule ^archives([/A-Za-z0-9]+)\.html index.php?url=/archives/$1.html [NC,L,QSA]
RewriteRule ^([0-9]+)[_\-][0-9a-z_\-]*\.html index.php?url=$1-article.html [L,NC,QSA]
RewriteRule ^feeds/(.*) index.php?url=/feeds/$1 [L,QSA]
RewriteRule ^unsubscribe/(.*)/([0-9]+) index.php?url=/unsubscribe/$1/$2 [L,QSA]
RewriteRule ^approve/(.*)/(.*)/([0-9]+) index.php?url=approve/$1/$2/$3 [L,QSA]
RewriteRule ^delete/(.*)/(.*)/([0-9]+) index.php?url=delete/$1/$2/$3 [L,QSA]
RewriteRule ^(admin|entries)(/.+)? index.php?url=admin/ [L,QSA]
RewriteRule ^archive/? index.php?url=/archive [L,QSA]
RewriteRule ^(index|atom[0-9]*|rss|b2rss|b2rdf).(rss|rdf|rss2|xml) rss.php?file=$1&ext=$2
RewriteRule ^(plugin|plugin)/(.*) index.php?url=$1/$2 [L,QSA]
RewriteRule ^search/(.*) index.php?url=/search/$1 [L,QSA]
RewriteRule ^(serendipity\.css|serendipity_admin\.css) index.php?url=/$1 [L,QSA]
RewriteRule ^index\.(html?|php.+) index.php?url=index.html [L,QSA]
RewriteRule ^htmlarea/(.*) htmlarea/$1 [L,QSA]
RewriteRule (.*\.html?) index.php?url=/$1 [L,QSA]
<Files *.tpl.php>
deny from all
</Files>
<Files *.tpl>
deny from all
</Files>
<Files *.sql>
deny from all
</Files>
<Files *.inc.php>
deny from all
</Files>
<Files *.db>
deny from all
</Files>
# END s9y
Posted: Wed Nov 08, 2006 8:23 pm
by docbrown
Still the same. Everything ok without the slash and an article not found with the slash.
Posted: Wed Nov 08, 2006 8:37 pm
by garvinhicking
Hi!
Could you tell me the URL to your blog?
Maybe you can edit your include/functions_permalinks.inc.php file and replace this:
Code: Select all
$PAT['UNSUBSCRIBE'] = '@/' . $serendipity['permalinkUnsubscribePath'].'/(.*)/([0-9]+)@';
$PAT['APPROVE'] = '@/' . $serendipity['permalinkApprovePath'].'/(.*)/(.*)/([0-9]+)@';
$PAT['DELETE'] = '@/' . $serendipity['permalinkDeletePath'].'/(.*)/(.*)/([0-9]+)@';
$PAT['ARCHIVES'] = '@/' . $serendipity['permalinkArchivesPath'].'([/A-Za-z0-9]+)\.html@';
$PAT['FEEDS'] = '@/' . $serendipity['permalinkFeedsPath'].'/@';
$PAT['ADMIN'] = '@/(' . $serendipity['permalinkAdminPath'] . '|entries)(/.+)?@';
$PAT['ARCHIVE'] = '@/' . $serendipity['permalinkArchivePath'] . '/?@';
$PAT['CATEGORIES'] = '@/' . $serendipity['permalinkCategoriesPath'].'/([0-9;]+)@';
$PAT['PLUGIN'] = '@/(' . $serendipity['permalinkPluginPath'] . '|plugin)/(.*)@';
$PAT['SEARCH'] = '@/' . $serendipity['permalinkSearchPath'] . '/(.*)@';
$PAT['COMMENTS'] = '@/' . $serendipity['permalinkCommentsPath'] . '/(.*)@';
$PAT['PERMALINK'] = '@' . serendipity_makePermalinkRegex($serendipity['permalinkStructure'], 'entry') . '@i';
$PAT['PERMALINK_CATEGORIES'] = '@' . serendipity_makePermalinkRegex($serendipity['permalinkCategoryStructure'], 'category') . '@i';
$PAT['PERMALINK_FEEDCATEGORIES'] = '@' . serendipity_makePermalinkRegex($serendipity['permalinkFeedCategoryStructure'], 'category') . '@i';
$PAT['PERMALINK_FEEDAUTHORS'] = '@' . serendipity_makePermalinkRegex($serendipity['permalinkFeedAuthorStructure'], 'author') . '@i';
$PAT['PERMALINK_AUTHORS'] = '@' . serendipity_makePermalinkRegex($serendipity['permalinkAuthorStructure'], 'author') . '@i';
with this:
Code: Select all
$PAT['UNSUBSCRIBE'] = '@/' . $serendipity['permalinkUnsubscribePath'].'/(.*)/([0-9]+)/?@';
$PAT['APPROVE'] = '@/' . $serendipity['permalinkApprovePath'].'/(.*)/(.*)/([0-9]+)/?@';
$PAT['DELETE'] = '@/' . $serendipity['permalinkDeletePath'].'/(.*)/(.*)/([0-9]+)/?@';
$PAT['ARCHIVES'] = '@/' . $serendipity['permalinkArchivesPath'].'([/A-Za-z0-9]+)\.html@';
$PAT['FEEDS'] = '@/' . $serendipity['permalinkFeedsPath'].'/?@';
$PAT['ADMIN'] = '@/(' . $serendipity['permalinkAdminPath'] . '|entries)(/.+)?@';
$PAT['ARCHIVE'] = '@/' . $serendipity['permalinkArchivePath'] . '/?@';
$PAT['CATEGORIES'] = '@/' . $serendipity['permalinkCategoriesPath'].'/([0-9;]+)/?@';
$PAT['PLUGIN'] = '@/(' . $serendipity['permalinkPluginPath'] . '|plugin)/(.*)@';
$PAT['SEARCH'] = '@/' . $serendipity['permalinkSearchPath'] . '/(.*)@';
$PAT['COMMENTS'] = '@/' . $serendipity['permalinkCommentsPath'] . '/(.*)@';
$PAT['PERMALINK'] = '@' . serendipity_makePermalinkRegex($serendipity['permalinkStructure'], 'entry') . '/?@i';
$PAT['PERMALINK_CATEGORIES'] = '@' . serendipity_makePermalinkRegex($serendipity['permalinkCategoryStructure'], 'category') . '/?@i';
$PAT['PERMALINK_FEEDCATEGORIES'] = '@' . serendipity_makePermalinkRegex($serendipity['permalinkFeedCategoryStructure'], 'category') . '/?@i';
$PAT['PERMALINK_FEEDAUTHORS'] = '@' . serendipity_makePermalinkRegex($serendipity['permalinkFeedAuthorStructure'], 'author') . '/?@i';
$PAT['PERMALINK_AUTHORS'] = '@' . serendipity_makePermalinkRegex($serendipity['permalinkAuthorStructure'], 'author') . '/?@i';
Best regards,
Garvin
Posted: Wed Nov 08, 2006 8:50 pm
by docbrown
Posted: Wed Nov 08, 2006 9:21 pm
by garvinhicking
Hi!
Okay, I just recreated the problem on my local setup.
It actually takes a bit more of patching to succeed. At this point of the serendipity release cycle I cannot add such a possibly intrusive patch to the distribution, but will do so with Serendipity 1.2
Meanwhile, you can use this patch:
http://svn.berlios.de/viewcvs/serendipi ... ks.inc.php
Apply those changes and then UNCOMMENT (remove the "//" in front of) the sections where it says "Patch for 1.2". When those lines are enabled, permalinks with an ending "/" are properly checked.
You will then also either need to resave your serendipity configuration so that an updated .htaccess will be written, or you keep the manual changes you applied earlier on with my instructions of this thread.
HTH,
Garvin
Posted: Wed Nov 08, 2006 9:59 pm
by docbrown
garvinhicking wrote:It actually takes a bit more of patching to succeed. At this point of the serendipity release cycle I cannot add such a possibly intrusive patch to the distribution, but will do so with Serendipity 1.2
Ack. Looking forward to version 1.2.
garvinhicking wrote:Meanwhile, you can use this patch:
Apply those changes and then UNCOMMENT (remove the "//" in front of) the sections where it says "Patch for 1.2". When those lines are enabled, permalinks with an ending "/" are properly checked.
You will then also either need to resave your serendipity configuration so that an updated .htaccess will be written, or you keep the manual changes you applied earlier on with my instructions of this thread.
Very well. I'll do so. Thank u very much for your help.