Plogger Support Forum - .htaccess and Cruft-Free URLs doubles slashes Thu, 28 Mar 2024 21:05:02 +0000 http://www.plogger.org/forum/ Lussumo Vanilla 1.1.10 .htaccess and Cruft-Free URLs doubles slashes http://www.plogger.org/forum/comments.php?DiscussionID=2925&Focus=11615#Comment_11615 http://www.plogger.org/forum/comments.php?DiscussionID=2925&Focus=11615#Comment_11615 Tue, 03 Nov 2009 07:35:41 +0000 Michael Tully
looked in the Database for trailing slashed under the Path section, not a thing

heres the the .htaccess


# BEGIN Plogger
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} !(\.|/$)
RewriteRule ^.*$ http://www.planet-templates.com%{REQUEST_URI}/ [R=301,L]
RewriteCond %{HTTP_HOST} !^www [NC]
RewriteRule ^(.*)$ http://www.planet-templates.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [S=2]
RewriteRule feed/$ plog-rss.php?path=%{REQUEST_URI} [L]
RewriteRule ^.*$ index.php?path=%{REQUEST_URI} [L]
</IfModule>
# END Plogger


here the URL

http://www.planet-templates.com

Cheers
Michael]]>
.htaccess and Cruft-Free URLs doubles slashes http://www.plogger.org/forum/comments.php?DiscussionID=2925&Focus=11714#Comment_11714 http://www.plogger.org/forum/comments.php?DiscussionID=2925&Focus=11714#Comment_11714 Wed, 11 Nov 2009 19:27:10 +0000 bloggus .htaccess and Cruft-Free URLs doubles slashes http://www.plogger.org/forum/comments.php?DiscussionID=2925&Focus=11715#Comment_11715 http://www.plogger.org/forum/comments.php?DiscussionID=2925&Focus=11715#Comment_11715 Wed, 11 Nov 2009 19:47:12 +0000 sidtheduck // if mod_rewrite is on and we're not embedded, remove the file basename
if ($config['use_mod_rewrite'] == 1 && $config['embedded'] == 0) {
$config['baseurl'] = 'http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']).'/';
// otherwise just use our cleaned up version of $_SERVER['PHP_SELF'] from plog-globals.php
} else {
$config['baseurl'] = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
}

and replace it with this:
// if mod_rewrite is on and we're not embedded, remove the file basename
if ($config['use_mod_rewrite'] == 1 && $config['embedded'] == 0) {
$config['baseurl'] = 'http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
// Verify URL for a trailing slash. If not, add one.
if ($config['baseurl']{strlen($config['baseurl'])-1} != '/') {
$config['baseurl'] = $config['baseurl'].'/';
}
// otherwise just use our cleaned up version of $_SERVER['PHP_SELF'] from plog-globals.php
} else {
$config['baseurl'] = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
}
]]>
.htaccess and Cruft-Free URLs doubles slashes http://www.plogger.org/forum/comments.php?DiscussionID=2925&Focus=11717#Comment_11717 http://www.plogger.org/forum/comments.php?DiscussionID=2925&Focus=11717#Comment_11717 Wed, 11 Nov 2009 20:16:00 +0000 bloggus .htaccess and Cruft-Free URLs doubles slashes http://www.plogger.org/forum/comments.php?DiscussionID=2925&Focus=11718#Comment_11718 http://www.plogger.org/forum/comments.php?DiscussionID=2925&Focus=11718#Comment_11718 Wed, 11 Nov 2009 20:19:57 +0000 sidtheduck .htaccess and Cruft-Free URLs doubles slashes http://www.plogger.org/forum/comments.php?DiscussionID=2925&Focus=11719#Comment_11719 http://www.plogger.org/forum/comments.php?DiscussionID=2925&Focus=11719#Comment_11719 Wed, 11 Nov 2009 20:20:58 +0000 bloggus .htaccess and Cruft-Free URLs doubles slashes http://www.plogger.org/forum/comments.php?DiscussionID=2925&Focus=11720#Comment_11720 http://www.plogger.org/forum/comments.php?DiscussionID=2925&Focus=11720#Comment_11720 Wed, 11 Nov 2009 20:22:04 +0000 bloggus http://www.domain.com//plogger-test-collection/album-1/492744-original/]]> .htaccess and Cruft-Free URLs doubles slashes http://www.plogger.org/forum/comments.php?DiscussionID=2925&Focus=11721#Comment_11721 http://www.plogger.org/forum/comments.php?DiscussionID=2925&Focus=11721#Comment_11721 Wed, 11 Nov 2009 20:24:10 +0000 sidtheduck .htaccess and Cruft-Free URLs doubles slashes http://www.plogger.org/forum/comments.php?DiscussionID=2925&Focus=11723#Comment_11723 http://www.plogger.org/forum/comments.php?DiscussionID=2925&Focus=11723#Comment_11723 Wed, 11 Nov 2009 20:27:53 +0000 bloggus
I found out that the actual $config['baseurl'] is http://www.domain.com\ - not a slash, but a backslash in the end

I changed the

if ($config['baseurl']{strlen($config['baseurl'])-1} != '/')


to

if ($config['baseurl']{strlen($config['baseurl'])-1} != '\\')


and not I got rid of the double slash.

Do you think it is the best way to do it? Do you know where this backslash is added?]]>
.htaccess and Cruft-Free URLs doubles slashes http://www.plogger.org/forum/comments.php?DiscussionID=2925&Focus=11724#Comment_11724 http://www.plogger.org/forum/comments.php?DiscussionID=2925&Focus=11724#Comment_11724 Wed, 11 Nov 2009 20:36:33 +0000 sidtheduck
Did your original URL look like this -> http://www.domain.com\/collection-name/album-name/picture.jpg ?]]>
.htaccess and Cruft-Free URLs doubles slashes http://www.plogger.org/forum/comments.php?DiscussionID=2925&Focus=11725#Comment_11725 http://www.plogger.org/forum/comments.php?DiscussionID=2925&Focus=11725#Comment_11725 Wed, 11 Nov 2009 20:37:51 +0000 bloggus
And No, that was the strangest thing. The URL looked like http://www.domain.com//collection-name/album-name/picture.jpg before the changes.]]>
.htaccess and Cruft-Free URLs doubles slashes http://www.plogger.org/forum/comments.php?DiscussionID=2925&Focus=11726#Comment_11726 http://www.plogger.org/forum/comments.php?DiscussionID=2925&Focus=11726#Comment_11726 Wed, 11 Nov 2009 20:42:56 +0000 bloggus .htaccess and Cruft-Free URLs doubles slashes http://www.plogger.org/forum/comments.php?DiscussionID=2925&Focus=11727#Comment_11727 http://www.plogger.org/forum/comments.php?DiscussionID=2925&Focus=11727#Comment_11727 Wed, 11 Nov 2009 20:45:01 +0000 sidtheduck
I'll do some more tests and see if there's an easy universal way to determine this for windows or linux. We're only running into issues here because dirname($_SERVER['PHP_SELF']) returns '/' or '\' instead of just being blank.
Let me know if you come across anything else in your testing as well.

p.s. what happens when you echo $_SERVER['PHP_SELF']'? Is there a backslash there?]]>
.htaccess and Cruft-Free URLs doubles slashes http://www.plogger.org/forum/comments.php?DiscussionID=2925&Focus=11728#Comment_11728 http://www.plogger.org/forum/comments.php?DiscussionID=2925&Focus=11728#Comment_11728 Wed, 11 Nov 2009 20:50:39 +0000 bloggus $_SERVER['PHP_SELF']

gives just /index.php

but

dirname($_SERVER['PHP_SELF'])

always gives \ in windows.

---

Maybe just runing
$config['baseurl'] = str_replace('\\', '/', $config['baseurl']);
after second line is all it is needed. That will at least solve WIndows issue.]]>
.htaccess and Cruft-Free URLs doubles slashes http://www.plogger.org/forum/comments.php?DiscussionID=2925&Focus=11729#Comment_11729 http://www.plogger.org/forum/comments.php?DiscussionID=2925&Focus=11729#Comment_11729 Wed, 11 Nov 2009 20:57:11 +0000 sidtheduck
Here is a slightly longer code that should work:
$config['baseurl'] = 'http://'.$_SERVER['HTTP_HOST'].str_replace('\\', '/', dirname($_SERVER['PHP_SELF']));
or maybe try this:
$config['baseurl'] = 'http://'.$_SERVER['HTTP_HOST'].realpath(dirname($_SERVER['PHP_SELF']));]]>
.htaccess and Cruft-Free URLs doubles slashes http://www.plogger.org/forum/comments.php?DiscussionID=2925&Focus=11730#Comment_11730 http://www.plogger.org/forum/comments.php?DiscussionID=2925&Focus=11730#Comment_11730 Wed, 11 Nov 2009 20:57:17 +0000 bloggus

// if mod_rewrite is on and we're not embedded, remove the file basename
if ( $config['use_mod_rewrite'] == 1 && $config['embedded'] == 0) {
$config['baseurl'] = 'http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
$config['baseurl'] = str_replace('\\', '/', $config['baseurl']);
// Verify URL for a trailing slash. If not, add one.
if ($config['baseurl']{strlen($config['baseurl'])-1} != '/') {
$config['baseurl'] = $config['baseurl'].'/';
}
// otherwise just use our cleaned up version of $_SERVER['PHP_SELF'] from plog-globals.php
}
else {
$config['baseurl'] = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
}
]]>
.htaccess and Cruft-Free URLs doubles slashes http://www.plogger.org/forum/comments.php?DiscussionID=2925&Focus=11731#Comment_11731 http://www.plogger.org/forum/comments.php?DiscussionID=2925&Focus=11731#Comment_11731 Wed, 11 Nov 2009 20:58:08 +0000 sidtheduck
Can you check the realpath() example?]]>
.htaccess and Cruft-Free URLs doubles slashes http://www.plogger.org/forum/comments.php?DiscussionID=2925&Focus=11732#Comment_11732 http://www.plogger.org/forum/comments.php?DiscussionID=2925&Focus=11732#Comment_11732 Wed, 11 Nov 2009 21:00:37 +0000 bloggus
Thanks! Will make a theme for this one, so maybe I will find more things in time!]]>
.htaccess and Cruft-Free URLs doubles slashes http://www.plogger.org/forum/comments.php?DiscussionID=2925&Focus=11733#Comment_11733 http://www.plogger.org/forum/comments.php?DiscussionID=2925&Focus=11733#Comment_11733 Wed, 11 Nov 2009 21:02:49 +0000 bloggus
realpath(dirname($_SERVER['PHP_SELF'])) gives just C:\]]>
.htaccess and Cruft-Free URLs doubles slashes http://www.plogger.org/forum/comments.php?DiscussionID=2925&Focus=13808#Comment_13808 http://www.plogger.org/forum/comments.php?DiscussionID=2925&Focus=13808#Comment_13808 Wed, 08 Jun 2011 03:43:21 +0000 ashkir