11bits
November 29, 2017, 7:02pm
1
It seems that Google always shows a trailing slash in the SERPs.
Ex: https://example.com/test/
And if I omit the blog folder using routes:
c::set('routes', array(
array(
'pattern' => '(:any)',
'action' => function($uid) {
$page = page($uid);
if(!$page) $page = page('blog/' . $uid);
if(!$page) $page = site()->errorPage();
return site()->visit($page);
}
),
array(
'pattern' => 'blog/(:any)',
'action' => function($uid) {
go($uid);
}
),
));
Then, the blog subpages URLs with a trailing slash doesn’t work. And all the visits from Google are 404 errors.
Is it possible to fix it changing the above code?
texnixe
November 29, 2017, 7:13pm
2
I think the main problem here is that your pages are available with and without slash, which ideally shouldn’t be the case. But rather, one should redirect to the other.
You can change or pattern like this:
'pattern' => '(:any)/',
Then it will work with the slash but not without. Or you have to make it optional.
But I’d suggest to decide for one and redirect everything else in your server config or .htaccess.
11bits
November 29, 2017, 7:32pm
3
OK, I removed the trailing slash following this setup:
@jenstornell :
I can save content from the panel with the following condition:
# make panel links work
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^panel/(.*) panel/index.php [L]
# remove trailing slash, but not for the panel
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/panel/.*$
RewriteCond %{REQUEST_URI} (.*)$
RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]
# make site links work
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCon…
And now it works fine.
Danke!