How to create routing for the pages

Hi, I have a pages folder there i have few pages ex: example.php, post.php, and my index.php inside site root, I do have header with navbar as php include. How do i create routing for those pages and use it in header.php(which is php include in index.php). I followed the docs but i get problem to make them work. It works for first click but if i click second time then again its routing to same routing as an seperate page and not found error thrown. such as below,

say / - for index.php and name of the routing is home
/example/ - example.php inside pages folder pages/example.php as URL,

when clicking first time on Example nav link, i go to /example/ and shows the correct page. if i click again on Example then it goes to pages/example/ (404 error). also if i click on home page while in example page, i go to /pages/ which 403 forbidden.

any help? or suggestion to solve this…appreciated.

Can you turn on debugging and provide a link so we can see what is going on and any errors?

I have followed this and did the routings… thanks anyway

here is the link: http://demo.satfocus.co.uk/
as i narrated here is HOME, OUR SERVICES/BURGLAR ALARM check those links. debug mode is enabled, when you click on BURGLAR ALARM under OUR SERVICES it goes to pages/burglaralarm
as i have that page inside pages folder. but while im there if i click on home page i get to /pages.
check this … thanks

Have you used site relative or document relative as a project setting?

This behaviour looks like document relative and should be site rather.

1 Like

First i had as document relative before i posted here i changed as site relative, but still the same

Can you make sure your href tag fo Home is set to / and you href tag for Burglar Alarm is set to /pages/burglaralarm/

I am assuming that you have a directory called pages, at /pages/ and then have multiple directories in that folder called burglaralarm at /pages/burglaralarm/ and in the burglaralarm folder you have an index.php file, is that assumption correct.

With site relative links / should always take the user back to the base directory

please find here the attached screenshot what i have in directory and routing

Also i checked href for both home and burglaralarm page, ./ and pages/burglaralarm is the value for href when selecting the routing for Link value

1 Like

In that case I would have.
Name: burglaralarm
Path: burglar-alarm
Url: /pages/burglaralarm.php

Then in your include file where you have your navigation, make sure that the href tag for home goes to just / and the href tag for burglaralrm is set to /page/burglaralarm.php

As far I would imagine that should do the trick.

Unfortunately because you started off as Document relative, the starting / was omitted from the href tags, and I do not imagine changing over to Site relative will auto fix that unless you at least open the include file possibly.

Thanks psweb, i notice that when selecting routing for home or burglaralarm its placing ./ and pages/burglaralarm

looks like bug in wappler mac 2.0.1,

It could be a bug, but probably more a (bug) that when altering the site from Document Relative to Site Relative, all files already made and linked with includes etc. are not rewritten to the Site Relative command.
As a document relative website, the link for the homepage when in the same directory would be / and when one directory up it would be …/ to take you a single directory back.
As a site relative website, the link for the homepage would always be / regardless of what directory you are in. I generally am always in Site Relative unless for very good reason.

To be utterly honest though, I am not even really sure why you are using routing in the first place, I mean for me the only reason why I would even use routing to begin with is under certain circumstances where I have a website that pulls all its data from a database and creates a page that is like a template.

Your directory structure you have shown, to me anyway does not really require routing, your site has navigation of the following

  1. HOME - links to index.php in your root directory
  2. OUR SERVICES - is a non linking placeholder for the submenu
    2a. BURGLAR ALARM - links to burglaralarm.php in the pages directory
    2b. CCTV - links to cctv.php in the pages directory
    2c. SATELLITE - links to satellite.php in the pages directory
    2d. TV AERIALS - links to tv-aerials.php in the pages directory
  3. OUR WORKS - links to our-works.php in the pages directory
  4. GET A QUOTE - can not see a link for this as yet
  5. CONTACT US - links to contact.php in the pages directory

So every page of the website has a corresponding .php file that is called when navigated to, therefore what need do you even have to use routing in the first place.

I would only use routing for situations like this
So for example, lets say I had a property / real-estate website

  1. I have a home page at the root of my site called index.php
  2. I have a directory called /properties/
  3. I have a single php file called index.php in the /properties/ directory.

As you can see my entire website now only has in total 2 pages, however I would like to show property listings for 100 properties all on that same single index.php file sitting in my /properties/ directory.

I start off where all 100 properties worth of data are stored on my sql database, and i design the /properties/index.php as a template that pulls each properties information from that database filtered by url query parameters, like index.php?prop=3 or index.php?prop=27 etc.

Now if a user was navigating my site they could see my homepage, and search for a property which would populate the filter query parameters of my properties page. Therefore that one single page acts like 100 separate pages, with different data and images etc.

The problem, is now two fold, first if a real estate agent wanted to navigate a client directly to a particular page over the telephone, they would have to say, go to http://www.example.com/properties/index.php?prop=72 and that is obviously not ideal it would be easier for the agent to tell the client to go to http://www.example.com/3-bed-texas-home

Second and more importantly, Google and SEO, the URL is a very important factor, and having the first example above indexed by Google honestly does nothing for the content of the page, while having the rewritten URL in the second example will certainly do far better.

I really hope this makes sense, and please do not be offended it is just my opinion, I would be interested to see what other users say about it too.

I really appreciate your time and long written explanation about routing and where it should be used. Now i clearly understood… :slight_smile: Thanks again psweb. i will remove and use when appropriate to use routing. so far i have no database or any other data come from API.

1 Like