Recent Topics

1 Dec 07, 2006 23:51    

Thanks balupton for reminding me of this thread. I use stubs and have checked the box for clean URLs, but my URLs are not as clean as people seem to want. I end up with domain.com/stubname.php/year/month/title. Good enough for me, but not for all players.

I think you can get the ".php" part out of there with b2evolution, but I've never tried it so can't say how to do it.

Would the ideal be something like domain.com/stubname/title? If so what happens when you have two posts with the same title? I'm curious is all - I have no skills in this direction and no answer available. Oh except for "if you know .htaccess you probably know a big piece of the answer".

2 Dec 07, 2006 00:49

To EdB,

Yeh you just write a .htaccess file that will take the url params appropriatly and then turn them into GET params and secretly redirect them to your index.php, so;
domain.com/user/ could turn into index.php?user=balupton or whatever.

I will be fiddling with the .htaccess way of doing it in january with one of my own projects, and will post back what i find i guess.

Is this helpful?

3 Dec 07, 2006 01:32

To my mind a good writeup on how to use .htaccess to redirect a "super clean url" to either a "regular b2evo url" or a "b2evo clean url" is a great idea. So many different things to always think about though.

What I always thought would be cool, and you might be able to do it, is a form type of thing that spits out the desired .htaccess file. Like webs that say "type in all your stuff here and this will make your metatags for you" type of thing. I have a really old javascript page that does that for metatags, but since I'm not hip to using .htaccess there is no point in me trying.

4 Dec 07, 2006 01:58

Hrmmm, that might be getting a bit advanced and technical... But we'll see how we go aye ;)

So right now clean urls don't use .htaccess files? Or just very limited ones...

I dug up one of my .htaccess files and just rewrote it to do that user thing i said above

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^user/(([\w\%]+)([/]?))$ index.php?user=$2 [nc]

Now that should turn
domain.com/blog/user/balupton to domain.com/blog/index.php?user=balupton but the user will still be using the clean url.

Hrmmm the biggest problem would be embedding this directly into b2evolution so links and such use clean urls. Maybe a plugin that rewrites the output of regenerate_url.

And sorry NoxDineen for hijacking your topic, EdB you think we should split the topic up into another one called 'Brainstorming clean urls with .htaccess' or something?

Edit: rewrote the regex in the .htaccess to handle the leading / correctly.

Edit Again: rewrote the regex in the .htaccess to handle '%'s correctly, e.g. %20.

Yet another edit:
Also here is one to handle domain.com/blog/date/2006/12/30

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^date/([\w\%]+)/([\w\%]+)/(([\w\%]+)[/]?)$ index.php?year=$1&month=$2&day=$4 [nc]

You should be able to figure the rest out EdB.

5 Dec 08, 2006 00:34

Ok EdB add these into your /blogs/ folder and be happy :)

Some hacks would need to be applied similar to this one;
http://forums.b2evolution.net/viewtopic.php?t=8089

See it working here;
http://packages.balupton.com/b2evo/date/2006/12/04
http://packages.balupton.com/b2evo/date/2006/12/06/personal
http://packages.balupton.com/b2evo/blog/personal
http://packages.balupton.com/b2evo/users/balupton note for this one, we will need a hack to turn names into ids, like i've mentioned above with the other topic.

Anyway here's the files.

6 Dec 08, 2006 17:08

Since I use b2evo at the root level what you're saying is I'm going to add 4 folders to the root, each of which contains one file?

7 Dec 08, 2006 22:20

Yep. Otherwise you would have one crazy regular expression.

8 Dec 08, 2006 22:52

Okay I was thinking that was the way but I figured I'd ask before making an assumption and asking my real question: how will it know to do anything? I mean what will make the server know I have those there if any URL doesn't actually engage those new folders?

9 Dec 08, 2006 22:59

eh... if i think i know what you mean, then i think this answer will answer it :S

Say if i go to
http://packages.balupton.com/b2evo/date/2006/12/04

Now the folders 2006/12/04 do not exist, and thats where the .htaccess file comes in, it uses a regular expression to read and modify the url into something else, so it translates
http://packages.balupton.com/b2evo/date/2006/12/04
to
http://packages.balupton.com/b2evo/index.php?m=20061204
or more specifically
http://packages.balupton.com/b2evo/date/../index.php?m=20061204

Now i have different directories set up that contain different .htaccess files that contain different ways to reformat the url.

Is this what you were asking?

10 Dec 08, 2006 23:06

Yes - that explains it. The inbound links currently don't mention those folders, but if an inbound link DOES mention it then it'll get redirected to the appropriate place. Thanks!

11 Dec 11, 2006 13:36

Hey EdB, are you planning to work on this?

Some changes that should be applied though it make it so they all require the blog name param, and atm they may not support underscores... or punctuation, i can add this support but you might want to have a fiddle and blow your mind ;)

12 Dec 11, 2006 15:27

I just uploaded the 4 folders but I gotta tell you the truth: I'm not sure what I can do with or about it. Seems to me if someone were to randomly produce a url that your work turned into a valid one then hooray, but how would I know? Also, and I should have thought before opening my mouth, but also I wonder what is the odds that someone will have in their mind the idea to randomly guess at a url?

So really I think what b2evo needs is a way to let a plugin rip up what IT makes as links and offer ultra-clean URLs for the public and search engines to feast on. In other words all my bloglink links should be something like "domain.com/blogshortname" and a smart .htaccess file should be able to understand what that means.

Anyway the folders are uploaded so I guess what I should do is see what types of URLs now find their way in. Once I get a handle on that I can play more and more. For now it's the time of week I go to work, so ... I get very little time at a nice keyboard and have to use it wisely. Or actually I have to ration it among my unwise choices, but to me it's the same thing.

13 Dec 16, 2006 20:00

I did some work on it, and now u just stick the .htaccess file in your root b2evo directory (e.g. you don't need those subdirectories anymore).

# Apache configuration for the blog folder


# this will select the default blog template to be displayed
# if the URL is just .../blogs/
<IfModule mod_dir.c>
	DirectoryIndex index.php index.html
</IfModule>


# this will make register globals off in b2's directory
# just put a '#' sign before these three lines if you don't want that
<IfModule mod_php4.c>
	php_flag register_globals off
</IfModule>

# If you're using Apache 2, you may wish to try this for clean URLs:
# AcceptPathInfo	On



# Here is the clean urls stuff, done by balupton
RewriteEngine On
Options +FollowSymlinks

# BLOG clean url
RewriteCond %{REQUEST_URI} /blog/.+$ [NC]
RewriteRule ^blog/([a-z0-9_\%]+)/?$ index.php?blog=$1 [L]

# DATE clean url
RewriteCond %{REQUEST_URI} /date/.+$ [NC]
RewriteRule ^date/([a-z0-9_\%]+)/?([a-z0-9\%]*)/?([a-z0-9\%]*)/?([a-z0-9\%]*)/?$ index.php?m=$1$2$3&blog=$4 [L]

# POST clean url
RewriteCond %{REQUEST_URI} /post/.+$ [NC]
RewriteRule ^post/([a-z0-9_\%]+)/?$ index.php?title=$1&more=1&c=1&tb=1&pb=1 [L]

# USER clean url
RewriteCond %{REQUEST_URI} /user/.+$ [NC]
RewriteRule ^user/([a-z0-9_\%]+)/?$ index.php?user=$1 [L]

edit: updated to support underscores

14 Dec 16, 2006 20:23

b2evo's new resolve_extra_path stuff is being mean, working on a fix now.

Heres the fix.

Add to _basic_config.php

/**
 * resolve_extra_path. It adds support for things like index.php/blog_urlname
 */
$resolve_extra_path = false;

And apply appropriatly in index.php

// Check if a specific blog has been requested in the URL:
param( 'blog', 'string', '', true ); 

if( empty($blog) )
{ // No blog requested by URL param, let's try to match something in the URL
	$Debuglog->add( 'No blog param received, checking extra path...', 'detectblog' );

	if( preg_match( '#^(.+?)index.php/([^/]+)#', $ReqHost.$ReqPath, $matches ) )
	{ // We have an URL blog name:
		$Debuglog->add( 'Found a potential URL blog name: '.$matches[2], 'detectblog' );
		if( (($Blog = & $BlogCache->get_by_urlname( $matches[2], false )) !== false) )
		{ // We found a matching blog:
			$blog = $Blog->ID;
		}
	}

	if( empty($blog) )
	{ // No blog identified by URL name, let's try to match the absolute URL
		if( preg_match( '#^(.+?)index.php#', $ReqHost.$ReqPath, $matches ) )
		{ // Remove what's not part of the absolute URL
			$ReqAbsUrl = $matches[1];
		}
		else
		{
			$ReqAbsUrl = $ReqHost.$ReqPath;
		}
		$Debuglog->add( 'Looking up absolute url : '.$ReqAbsUrl, 'detectblog' );

		if( (($Blog = & $BlogCache->get_by_url( $ReqAbsUrl, false )) !== false) )
		{ // We found a matching blog:
			$blog = $Blog->ID;
			$Debuglog->add( 'Found matching blog: '.$blog, 'detectblog' );
		}
	}

	if( empty($blog) )
	{ // Still no blog requested, use default
		$blog = $Settings->get('default_blog_ID');
		$Debuglog->add( 'Using default blog '.$blog, 'detectblog' );
	}

	if( empty($blog) )
	{ // No specific blog to be displayed:
		// we are going to display the default page:
		require dirname(__FILE__).'/default.php';
		exit();
	}
	
} elseif( !is_numeric($blog) )
{	// We have an URL blog name:
	$Debuglog->add( 'Found a potential URL blog name: '.$blog, 'detectblog' );
	if( (($Blog = & $BlogCache->get_by_urlname( $blog, false )) !== false) )
	{	// We found a matching blog:
		$blog = $Blog->ID;
	
	} elseif( $blog = $Settings->get('default_blog_ID') )
	{	// Still no blog requested, use default
		$Debuglog->add( 'Using default blog '.$blog, 'detectblog' );
		
	} else
	{	// No specific blog to be displayed:
		// we are going to display the default page:
		require dirname(__FILE__).'/default.php';
		exit();
	}
}
settype($blog,'integer');


Form is loading...