Jump to content

Routing users to url segments once on the site


louisstephens
 Share

Recommended Posts

So I have a project coming up soon and one of the goals was to use Google's AMP project for the project's mobile site. I have gone through the tutorials and think I have a good grasp on the matter, but there is still one roadblock I do not really know how to tackle. The site, which uses a responsive grid system, will look great on a mobile and desktop which was is fine by me. However, if a user comes from Google to one of our AMP pages (ie www.example.com/amp) and clicks on a url, they will then be loading our responsive mobile pages and not the amp pages. For the sake of consistency, we really want to "force" users to stay on all the amp pages.

 

My current thoughts on how to set up this task:

  1. Allow url segments for all pages using "/amp"
  2. Using a simple if statement, load the amp page if it exists
<?php
if($input->urlSegment1) { // add "&& $input->urlSegment1 == 'amp'" if you've more urlSegments
	include("partials/amp-page.php"); 
}
else {
	include("partials/normal.php"); 
}
?>

 

However, I have hit a roadblock on appending "/amp" to all pages if they came to an amp page via Google, or even if they are on mobile and visit the site. Is this even possible to do, or should we just use the amp pages (if a user comes from google) and allow them to be active on our mobile pages?  We are just trying to give the fastest load times possible, as well as give a consistent look between mobile and desktop versions. As always, I really appreciate the ideas and help.

Link to comment
Share on other sites

Maybe you can hook Page::path and check if there is urlSegment and then append /amp/. 

wire()->addHookAfter("Page(template=news)::path", function($e) {
	$input = wire('input');
	if($input->urlSegment1) {
		$e->return = $e->return . "amp/";
	}	
});

In that way, if a user visits AMP version of a page all links will be linked to AMP versions of other pages. 

  • Like 4
Link to comment
Share on other sites

  • 1 year later...
 
 
 
On 3/1/2018 at 11:41 AM, louisstephens said:

However, I have hit a roadblock on appending "/amp" to all pages if they came to an amp page via Google, or even if they are on mobile and visit the site. Is this even possible to do, or should we just use the amp pages (if a user comes from google) and allow them to be active on our mobile pages?  We are just trying to give the fastest load times possible, as well as give a consistent look between mobile and desktop versions. As always, I really appreciate the ideas and help.

Hi Louis, just curious to know if you were able to get this working - I have the exact same situation and haven't been able to find anything helpful in the PW forums. If so, any chance you could post your working code for the navigation?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...