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

Trailing slashes fixed (URL should have end slashes in SEO) #23

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions src/PrerenderMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,11 @@ private function getPrerenderedPageResponse($request)

try {
// Return the Guzzle Response
$host = $request->getHost();
$path = $request->Path();
// Fix "//" 404 error
if ($path == "/") {
$path = "";
}
return $this->client->get($this->prerenderUri . '/' . urlencode($protocol.'://'.$host.'/'.$path), compact('headers'));
$host = $request->getHost();
// Set path to request URI for fix trailing slashes (URL should have end slashes in Seo)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whether a URL should end in a slash or whether a website has URLs that end in a slash or not should be up to the website and not enforced in this middleware since that could break things for people already using this without a trailing slash.

$path = $request->getRequestUri();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this actually add a trailing slash? It looks like you only removed the slash between $host and $path since I assume getRequestUri returns the path with the "/" at the beginning of the string? Is there documentation anywhere on getRequestUri() vs Path()?


return $this->client->get($this->prerenderUri . '/' . urlencode($protocol.'://'.$host . $path), compact('headers'));
} catch (RequestException $exception) {
if(!$this->returnSoftHttpCodes && !empty($exception->getResponse()) && $exception->getResponse()->getStatusCode() == 404) {
\App::abort(404);
Expand Down