• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

XF 1.1 URLs (& Pages)

Razasharp

Well-known member
#1
Is it possible to change (via file edits if need be) the url of the forum homepage?

I'd want it to be the same as my current forum so we don't lose our place in the search engines. So instead of site.com being the forum index, I'd prefer site.com/my-forum.php (or site.com/my-forum)
(In vB we just needed to rename index.php to whatever we wanted, then specify that in the ACP.)

Also, can the 'pages' system (via ACP) be used to create a homepage? Which can pull in data from the DB? (Such as latest threads.) Could it also be used to create other pages, e.g site.com/section-two site.com/section-three etc, where each of these 'pages' could in turn pull different data from the DB too? (If anyone's familiar with logicians Webtemplates that's the sort end result I'm after.)

Also, minor detail, but is it possible to change the default /forums/forum-name to singular forum/forum-name ?

Hope these are possible.
 

Jake Bunce

XenForo moderator
Staff member
#2
This addon lets you change the routes:

http://xenforo.com/community/resources/route-changer.447/

There is no configurable option to change the name of "index.php". But with friendly URLs enabled the "index.php" is not visible, and everything uses routes which can be changed with that addon. You can change the "empty route" with that addon too. It's called "index".

Also, can the 'pages' system (via ACP) be used to create a homepage? Which can pull in data from the DB? (Such as latest threads.) Could it also be used to create other pages, e.g site.com/section-two site.com/section-three etc, where each of these 'pages' could in turn pull different data from the DB too? (If anyone's familiar with logicians Webtemplates that's the sort end result I'm after.)
That is possible by creating a callback function for your page node. Here is a basic code example of a callback which can serve as a skeleton for your purposes:

http://xenforo.com/community/thread...er-custom-fields-on-a-page.33744/#post-384478

And here is another code example showing how you can check the domain name:

http://xenforo.com/community/resources/different-style-per-domain-code-example.394/

The page node callback makes the $controller available to you, so you can use the same code to check the domain in your page node callback.
 

Razasharp

Well-known member
#3
This addon lets you change the routes:

http://xenforo.com/community/resources/route-changer.447/

There is no configurable option to change the name of "index.php". But with friendly URLs enabled the "index.php" is not visible, and everything uses routes which can be changed with that addon. You can change the "empty route" with that addon too. It's called "index".



That is possible by creating a callback function for your page node. Here is a basic code example of a callback which can serve as a skeleton for your purposes:

http://xenforo.com/community/thread...er-custom-fields-on-a-page.33744/#post-384478

And here is another code example showing how you can check the domain name:

http://xenforo.com/community/resources/different-style-per-domain-code-example.394/

The page node callback makes the $controller available to you, so you can use the same code to check the domain in your page node callback.
Wow the route changer is awesome - exactly what I needed :) (reckon this should be part of the core - it is so useful!! :D)

Re the pages and callback functions, I guess I can include many queries? So I might have a page and on it I'd like to show, say the latest threads, latest members who have joined, and latest threads from the news section - would that be possible? (I have forgotten all the PHP I knew, so I will have to brush up on it again.)

Thanks again for your help Jake - you are such a super star!
 

Jake Bunce

XenForo moderator
Staff member
#4
Re the pages and callback functions, I guess I can include many queries? So I might have a page and on it I'd like to show, say the latest threads, latest members who have joined, and latest threads from the news section - would that be possible? (I have forgotten all the PHP I knew, so I will have to brush up on it again.)
Yes.
 

HenrikHansen

Well-known member
#6
(In vB we just needed to rename index.php to whatever we wanted, then specify that in the ACP.)

Also, can the 'pages' system (via ACP) be used to create a homepage? Which can pull in data from the DB? (Such as latest threads.) Could it also be used to create other pages, e.g site.com/section-two site.com/section-three etc, where each of these 'pages' could in turn pull different data from the DB too? (If anyone's familiar with logicians Webtemplates that's the sort end result I'm after.)
Most of this can be done by using the widget framework
http://xenforo.com/community/resources/bd-widget-framework.297/
 

Razasharp

Well-known member
#9
This addon lets you change the routes:

http://xenforo.com/community/resources/route-changer.447/

There is no configurable option to change the name of "index.php". But with friendly URLs enabled the "index.php" is not visible, and everything uses routes which can be changed with that addon. You can change the "empty route" with that addon too. It's called "index".
Is there a way to override the root url of the domain Jake? I usually use this in my .htaccess:

Code:
RewriteRule ^$ /my-index-page.htm [L]
With XF, I'd like the root (mysite.com) to display one of my XF 'Pages'. Would that be possible?

Also, is there a way to force www? I usually use this:

Code:
# force www..
RewriteCond %{HTTP_HOST} !^www\. [NC].
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
But it seems to be conflicting with the default XF rules.
 

Jake Bunce

XenForo moderator
Staff member
#10
Is there a way to override the root url of the domain Jake? I usually use this in my .htaccess:

Code:
RewriteRule ^$ /my-index-page.htm [L]
With XF, I'd like the root (mysite.com) to display one of my XF 'Pages'. Would that be possible?
This doesn't work in my experience. It obscures the URI which XenForo relies on. A different approach is required.

I suspect this small addon might work with your rewrite (instead of a page node). I haven't tested it, but I think it will work:

http://xenforo.com/community/resources/kotomi-generic-script-bridge.122/

Also, is there a way to force www? I usually use this:

Code:
# force www..
RewriteCond %{HTTP_HOST} !^www\. [NC].
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
But it seems to be conflicting with the default XF rules.
See this recent post of mine:

http://xenforo.com/community/threads/redirect-not-working.34370/#post-390828

The .htaccess file is in your forum root. And be sure to include the subdirectory (e.g. /forum) or not depending on if your forum is in the web root or not.
 

Razasharp

Well-known member
#11
See this recent post of mine:

http://xenforo.com/community/threads/redirect-not-working.34370/#post-390828

The .htaccess file is in your forum root. And be sure to include the subdirectory (e.g. /forum) or not depending on if your forum is in the web root or not.
Thanks Jake - that works brilliantly!

This doesn't work in my experience. It obscures the URI which XenForo relies on. A different approach is required.

I suspect this small addon might work with your rewrite (instead of a page node). I haven't tested it, but I think it will work:

http://xenforo.com/community/resources/kotomi-generic-script-bridge.122/
I am kinda reluctant to rely on a mod for something that could break the site in such a drastic way in future (if the mod author decides to abandon the project). I know I will be relying on your routes mod, but you are pretty much a constant here :) and I doubt you will go awol, hence I feel a lot more confortable with my XF site being highly dependent on your mod.

Is there anyway you could add this to your routes mod? It seems to fit in nicely with it. Perhaps something like:

root -> pages-file

So that the root of the domain goes to an XF 'page' (one created in ACP > Node tree > Create new page).

I think these things and your mod should be seriously considered for the core product too, as they are just so essential imo.
 

Jake Bunce

XenForo moderator
Staff member
#12
Is there anyway you could add this to your routes mod? It seems to fit in nicely with it. Perhaps something like:

root -> pages-file

So that the root of the domain goes to an XF 'page' (one created in ACP > Node tree > Create new page).
Nope. The name of the route can be changed using the Route Changer, but it can't be removed.

The Route Changer does allow you to change the "index" route which is the empty route. So theoretically you could do:

pages -> index

But this doesn't work as you would expect because 'pages' is not a "simple" route in that it has parameters in the URL (after the 'pages' part). The route must not use any extra parameters for it to be empty. Otherwise XenForo will show the empty route like this in the URL:

/index/parameters/

To make this idea work you would have to create a new "simple" route with an addon (not using a page node). The you can use the Route Changer like you want.
 

Razasharp

Well-known member
#13
Nope. The name of the route can be changed using the Route Changer, but it can't be removed.

The Route Changer does allow you to change the "index" route which is the empty route. So theoretically you could do:

pages -> index

But this doesn't work as you would expect because 'pages' is not a "simple" route in that it has parameters in the URL (after the 'pages' part). The route must not use any extra parameters for it to be empty. Otherwise XenForo will show the empty route like this in the URL:

/index/parameters/

To make this idea work you would have to create a new "simple" route with an addon (not using a page node). The you can use the Route Changer like you want.
Thanks for the explantation and taking the time to reply Jake.

Are you aware of any guides here that show you how to create a 'simple' route?

Also, could I just edit the files to change the url of the root? I still need the index route (which I have changed via your mod) as it will point to the forums. (Or I need some other way to point to the forums.)

The Xenporta mod seems to achieve this, as the root goes to the portal, and the forums are at /forums - I'm just not sure how they do it.
 

Jake Bunce

XenForo moderator
Staff member
#14
Are you aware of any guides here that show you how to create a 'simple' route?
Basically you create a new route:

Admin CP -> Development -> Route Prefixes

You will need to specify a route handler. Look in library/XenForo/Route/Prefix for examples. At the very least you need a match() function. This is a basic match function. No special parameters:

Code:
<?php

class YourAddon_Route_Prefix_Index implements XenForo_Route_Interface
{
	public function match($routePath, Zend_Controller_Request_Http $request, XenForo_Router $router)
	{
		return $router->getRouteMatch('YourAddon_ControllerPublic_Index', 'index', 'tabid');
	}
}
Then you need to create your controller which is returned by your route handler (YourAddon_ControllerPublic_Index in the above example, with an action of 'index'). Here is a simple example of a controller:

Code:
<?php

class YourAddon_ControllerPublic_Index extends XenForo_ControllerPublic_Abstract
{
	public function actionIndex()
	{
		$viewParams = array(
			// 'var' => $value
		);

		return $this->responseView('YourAddon_ViewPublic_View', 'template_name', $viewParams);
	}
}
Then create the template named by the controller (template_name in the above example). You don't have to create the view class (YourAddon_ViewPublic_View in the above example).

Now you have a simple route that loads one page, and that route can be assigned to the 'index' route with the Route Changer addon.
 

Jake Bunce

XenForo moderator
Staff member
#15
Also, could I just edit the files to change the url of the root? I still need the index route (which I have changed via your mod) as it will point to the forums. (Or I need some other way to point to the forums.)
You can do a double swap. An example is given at the bottom of the description. It shows how to recreate XenPorta's index swap using this addon:

http://xenforo.com/community/resources/route-changer.447/
 

Razasharp

Well-known member
#16
Basically you create a new route:

Admin CP -> Development -> Route Prefixes

You will need to specify a route handler. Look in library/XenForo/Route/Prefix for examples. At the very least you need a match() function. This is a basic match function. No special parameters:

Code:
<?php
 
class YourAddon_Route_Prefix_Index implements XenForo_Route_Interface
{
public function match($routePath, Zend_Controller_Request_Http $request, XenForo_Router $router)
{
return $router->getRouteMatch('YourAddon_ControllerPublic_Index', 'index', 'tabid');
}
}
Then you need to create your controller which is returned by your route handler (YourAddon_ControllerPublic_Index in the above example, with an action of 'index'). Here is a simple example of a controller:

Code:
<?php
 
class YourAddon_ControllerPublic_Index extends XenForo_ControllerPublic_Abstract
{
public function actionIndex()
{
$viewParams = array(
// 'var' => $value
);
 
return $this->responseView('YourAddon_ViewPublic_View', 'template_name', $viewParams);
}
}
Then create the template named by the controller (template_name in the above example). You don't have to create the view class (YourAddon_ViewPublic_View in the above example).

Now you have a simple route that loads one page, and that route can be assigned to the 'index' route with the Route Changer addon.
Thanks for taking the time to explain - I really appreciate it! I am sure I am your biggest fan lol, can you remember how much you helped me with vB in the early days? I never forgot.

Anyway back to this - I see what you mean now, I was worried that if I change the index route the forum link (that is changed in another route changer custom route) would break... but I tried it and it still works :0 so now I just need to figure out creating the simple route, but I'll do that after setting up the dev environment for XF. Now that I know it's possible I can do that - I just wanted to make sure that I could at least get the basic structure of the site sorted before diving in.

I need to read up on PHP and Zend first as I've totally forgotten all the PHP I knew. Have you got any tips for learning PHP (and zend) for XF development? I know OOP/Ruby/Rails - so a crash course should do just fine lol.

Thanks again for your help I really do appreciate it.
 

Jake Bunce

XenForo moderator
Staff member
#17

Razasharp

Well-known member
#18
Basically you create a new route:

Admin CP -> Development -> Route Prefixes

You will need to specify a route handler. Look in library/XenForo/Route/Prefix for examples. At the very least you need a match() function. This is a basic match function. No special parameters:

Code:
<?php
 
class YourAddon_Route_Prefix_Index implements XenForo_Route_Interface
{
public function match($routePath, Zend_Controller_Request_Http $request, XenForo_Router $router)
{
return $router->getRouteMatch('YourAddon_ControllerPublic_Index', 'index', 'tabid');
}
}
Then you need to create your controller which is returned by your route handler (YourAddon_ControllerPublic_Index in the above example, with an action of 'index'). Here is a simple example of a controller:

Code:
<?php
 
class YourAddon_ControllerPublic_Index extends XenForo_ControllerPublic_Abstract
{
public function actionIndex()
{
$viewParams = array(
// 'var' => $value
);
 
return $this->responseView('YourAddon_ViewPublic_View', 'template_name', $viewParams);
}
}
Then create the template named by the controller (template_name in the above example). You don't have to create the view class (YourAddon_ViewPublic_View in the above example).

Now you have a simple route that loads one page, and that route can be assigned to the 'index' route with the Route Changer addon.
Hi Jake, sorry to be a pain but I tried the above and it keeps saying it can't find a controller :/

Here is my code:

library/XenForo/ControllerPublic/Home.php
PHP:
<?php
 
 class RootChanger_ControllerPublic_Home extends XenForo_ControllerPublic_Abstract
 {
  public function actionIndex()
  {
    $viewParams = array(
      // 'var' => $value
    );
 
    return $this->responseView('RootChanger_ViewPublic_View', 'rootchanger_template', $viewParams);
  }
 }

library/XenForo/Route/Prefix/Home.php
PHP:
 <?php
 
 class RootChanger_Route_Prefix_Home implements XenForo_Route_Interface
 {
  public function match($routePath, Zend_Controller_Request_Http $request, XenForo_Router $router)
  {
    return $router->getRouteMatch('RootChanger_ControllerPublic_Home', 'index');
  }
 }
And I created a template called 'rootchanger_template' and a public route prefix called home, and the route class as:
RootChanger_Route_Prefix_Home

Have I messed up with the naming conventions or something? :confused:
 

Jake Bunce

XenForo moderator
Staff member
#19
The class name must match the location of the file. That's how the name space works:

RootChanger_ControllerPublic_Home = library/RootChanger/ControllerPublic/Home.php

The same goes for your route handler.
 

Razasharp

Well-known member
#20
Awesome it works!!
The class name must match the location of the file. That's how the name space works:

RootChanger_ControllerPublic_Home = library/RootChanger/ControllerPublic/Home.php

The same goes for your route handler.
AWESOME it works!!! Thanks Jake!!! :)

I think that now, along with your routes mod is just what I was crying out for back in the vB days - hopefully we're gonna have some fun with this, and use XF to power lots of none forums sections, like articles, news, blogs etc. Will let you know how it goes, and thanks again for you help.