Implemented  Please provide the Standard URL option

AndyB

Well-known member
I hope there will be an option in the admin cp to choose Standard URLs. I really dislike Friendly URLs and hope we are not forced to use them on our own forums.

Perhaps Kier or Mike could provide and example of what the Standard URL would look like to display the following:

1) a forum
2) a thread
3) a post within a thread
4) an attachment

Thank you.
 
Upvote 0
This suggestion has been implemented. Votes are no longer accepted.
The only URL format there which does not require a rewrite rule (either through .htaccess or another server configuration method) is the one that includes index.php.

Hi Kier,

Could you expand on this a bit for us. How does xenForo do the rewite rule? Does it use a .htaccess of some other server configuration method?

Would there be any benefit it asking for index.php be part of the URL so we can avoid using a .htaccess or some other server configuration method?

Thank you.
 
Hi Kier,

Could you expand on this a bit for us. How does xenForo do the rewite rule? Does it use a .htaccess of some other server configuration method?

Would there be any benefit it asking for index.php be part of the URL so we can avoid using a .htaccess or some other server configuration method?

Thank you.

with the index.php in place, it'll read the query string for the path. Without this, it will require some sort of rewrite (.htaccess, or similar)
 
XenForo uses a single very simple rewrite rule, which translates as the following:

If the request does not point to an existing directory, file or symlink, load index.php.

That's it. If you have access to a rewriting server, which most people do, there is no measurable performance penalty for employing such a simple rewrite, so there is no reason whatsoever to choose the non-rewrite version (that includes index.php in the URL) unless you can't use URL rewriting.
 
XenForo uses a single very simple rewrite rule, which translates as the following:

If the request does not point to an existing directory, file or symlink, load index.php.

That's it. If you have access to a rewriting server, which most people do, there is no measurable performance penalty for employing such a simple rewrite, so there is no reason whatsoever to choose the non-rewrite version (that includes index.php in the URL) unless you can't use URL rewriting.
This is a bit off topic, but I just wrote a small web app and used this rewriting method because I thought it was a great idea (everything to index.php). I then used regexes to basically do something like this:
PHP:
if(preg_match('/^members(\/[A-Z]+-[A-Z]+\.[0-9]+)?$/i', $trimmed_url, $matches)) {
     //members code
} else if(preg_match('/^home$/i', $trimmed_url, $matches)) {
     //homepage code
} else {
     send_error(404);
}
Now, obviously this is hard to maintain and is designed quite poorly, but I'm wondering if you could provide some insight into how you handle the URL's internally. I assume you pass it to some kind of controller, but I'm fuzzy on how that would actually work. :)

Please tell me it isn't
PHP:
if($do == 'members') {
     // code
} else if ($do == 'threads') {
    // code
}
or something similar. :D
 
The first part of the URL after /community/ (which is the directory in which we have installed XenForo) is known as the Route Prefix. We can simply extract that segment then look for a matching router component to handle the URL. Prefixes are registered in the DB and point to a route prefix class that does the work.

Simple, efficient, extensible and fast :)
 
This is the router code for the /profile-posts/ prefix:
PHP:
<?php

/**
 * Route and link builder for profile post-related actions.
 *
 * @package XenForo_ProfilePost
 */
class XenForo_Route_Prefix_ProfilePosts implements XenForo_Route_Interface
{
	/**
	 * Match a specific route for an already matched prefix.
	 *
	 * @see XenForo_Route_Interface::match()
	 */
	public function match($routePath, Zend_Controller_Request_Http $request, XenForo_Router $router)
	{
		$action = $router->resolveActionWithIntegerParam($routePath, $request, 'profile_post_id');
		return $router->getRouteMatch('XenForo_ControllerPublic_ProfilePost', $action, 'members');
	}

	/**
	 * Method to build a link to the specified page/action with the provided
	 * data and params.
	 *
	 * @see XenForo_Route_BuilderInterface
	 */
	public function buildLink($originalPrefix, $outputPrefix, $action, $extension, $data, array &$extraParams)
	{
		return XenForo_Link::buildBasicLinkWithIntegerParam($outputPrefix, $action, $extension, $data, 'profile_post_id');
	}
}
 
The first part of the URL after /community/ (which is the directory in which we have installed XenForo) is known as the Route Prefix. We can simply extract that segment then look for a matching router component to handle the URL. Prefixes are registered in the DB and pass reference a route prefix class that does the work.

Simple, efficient, extensible and fast :)
Awesome. I assume this means that addons can add prefixes to the DB and register their own router classes? :)
 
Nice code, although I admit I don't know enough about PHP's OOP (or OOP in general) to understand a lot of it. I must say, though, that the buildLink method is appealing. :D

Have you considered writing a tool to find all valid URL's referenced within posts, profile posts, etc. and translate them if the URL structure is ever changed? Seeing as the URL structure already needs to be strictly defined with the router prefix stuff, I would think it would be trivial to find all the URL's within content on the forum and use the same functions to parse and then rebuild the links. :)
 
It might look ugly, but that's why some people are proponents of this:
PHP:
if ('string literal' == $variable)
{
    // something
}
And please accept my apologies Eriksrocks.
 
Hi Kier,

Could you expand on this a bit for us. How does xenForo do the rewite rule? Does it use a .htaccess of some other server configuration method?

Would there be any benefit it asking for index.php be part of the URL so we can avoid using a .htaccess or some other server configuration method?

Thank you.
I think now we are FINALLY getting to the bottom of this issue after 4 pages. What is your major malfunction with .htaccess files?

They are a perfectly normal, acceptable, legal approach to configuring a web server. The entire documentation of Apache web server encourages you and fully documents how to use .htaccess files.


And just to stay on topic, I promise I have never had a problem with == vs = in PHP. ;) Never ever. Not never. Ok maybe once. Urrrrrrgggghhhh!!! 1 hour of my life I will never get back.
 
Top Bottom