Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All links in cached page appended with ?stage=Live in SS3.7.3 #102

Closed
TomDownard opened this issue Jun 10, 2019 · 6 comments
Closed

All links in cached page appended with ?stage=Live in SS3.7.3 #102

TomDownard opened this issue Jun 10, 2019 · 6 comments

Comments

@TomDownard
Copy link

Any links in pages generated through the Sitetree Link() function are being appended with "?stage=Live" in the cached files. This is an issue for SEO reasons, as the same content is being served on two urls.

For example, when looping through dataobjects in a template:

<% loop $Apartments %>
	<a href="$Link">$Title</a>
<% end_loop %>

This would result in a URL like: /apartmtent_title?stage=Live being output.

I have tried overriding the Link function in Page.php:

public function Link($action = null) {
	$relativeLink = $this->RelativeLink($action);
	$link = Controller::join_links(Director::baseURL(), $relativeLink);
	$this->extend('updateLink', $link, $action, $relativeLink);
	if(strpos($link, '?stage=Live') !== false){
		$link = str_replace("stage=Live&", "", $link);
		$link = str_replace("stage=Live", "", $link);
	}
	return $link;
}

However this results in staged content being included in the cache in loops such as above.

Has anybody come across this issue or a solution for it?

@mediabeastnz
Copy link

+1 also having this issue

@mediabeastnz
Copy link

In the file URLArrayObject.php and function sanitize_url() there are a few $_GET variables unset. Should stage not be added to this e.g.

unset($getVars['_ID'], $getVars['_ClassName'], $getVars['stage']);

Applying this patch seems to resolve the issue for me but doesn't really touch on why the stage is in the URL in the first place.

@NightJar
Copy link

NightJar commented Sep 25, 2019

This is probably a hang over from the alteration to not store global state between requests - it was causing confusion with editors viewing draft content without realising, as there was no indication.

Remember the old days when ?Stage=draft would set a session var, then every request regardless of GET param would always be draft? This might be caused by the job being queued from within the CMS, or is a hangover from ensuring that the live site is cached.

This is all out loud thoughts, in case anyone wants to take a look and maybe submit a PR for HacktoberFest ;)
If so, please see https://docs.silverstripe.org/en/4/contributing/code/ about the SilverStripe process about branching and making PRs against the correct branches :)

I say this because even though the module is marked as supported, this is the SilverStripe 3 compatible version - which is in security support only.
Alternatively if you can reproduce this issue with SilverStripe 4, this is more likely to be prioritised to be looked at.

@emteknetnz
Copy link
Member

emteknetnz commented Dec 10, 2019

Related #100

@quamsta
Copy link
Contributor

quamsta commented Sep 29, 2020

If anyone is still having an issue with this, I had to implement a hacky fix on an old site we needed to statically generate due to some unexpectedly high traffic to it. In FilesystemPublisher.php, around line 305, I added some code to strip out ?stage=Live in the to-be-saved .html cached file after the if-statment:

"if (Config::inst()->get('FilesystemPublisher', 'include_caching_metadata')) {":

$content = str_replace( '?stage=Live', '',$content );

@dhensby
Copy link
Contributor

dhensby commented May 20, 2021

I'm not sure if this is fixed, but I'm afraid v3 is out of support now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants