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

Conversation

FarhadKh
Copy link

URL should have end slashes in SEO.
URL without end slash should redirect with 301 status to URL with end slash.
E.g. https://github.com/jeroennoten/Laravel-Prerender redirect to https://github.com/jeroennoten/Laravel-Prerender/
So $path changed to request URI.
What's the use of this codes?

if ($path == "/") {
      $path = "";
}

I think It just removes end slash from home page that It's not good for Seo

@thoop
Copy link
Contributor

thoop commented Jan 23, 2019

It looks like that is checking for a path equal to "/" and not any path ending in "/". Also it looks like the comment for that line is:

// Fix "//" 404 error
if ($path == "/") {	
    $path = "";	
}

So I think that has a different purpose than what you described unless there is a different piece of code that is adding a trailing slash.

@FarhadKh
Copy link
Author

@thoop I know that code.
but we need path equal to "/"
This code
$path = $request->Path();
makes the same path for request with end slash and without end slash!
Then I changed to
$path = $request->getRequestUri();
for fix it.
If everybody has not found error on "//" request.
It seems their routing system has errors!

}
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.

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)
$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()?

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

Successfully merging this pull request may close these issues.

2 participants