My site is redirecting wwwdotsitedocodotuk/indexdothtml to wwwdotsitedocodotuk successfully but Google search console is giving me: Alternative page with proper canonical tag ‘index’ - so in other words it’s redirecting index.html to the base url but index isn’t redirecting. What am I missing here? Thank you.
Is this the same issue as in this thread?
It’s kind of the same issue and I’ve read through that a few times but on my site index.html is redirecting properly. Hy home page alias is ‘index’. I’d considered setting it to index.html but not sure of the consequences.
mydomain.com/index behaves weird on my test-environment as well. It seems to me that Apache automatically alters the request to mydomain.com/index.php, which then (from the MODX point of view) looks the same as a request to mydomain.com/.
You could create a plugin like this (that runs on the event OnHandleRequest) to log the requests:
<?php
$eventName = $modx->event->name;
switch($eventName) {
case 'OnHandleRequest':
if ($modx->context->get('key') != "mgr") {
$requestUri = $_SERVER['REQUEST_URI'] ? $_SERVER['REQUEST_URI'] : 'unknown';
$reqestParam = $modx->getOption('request_param_alias', null, 'q');
$identifier = isset($_REQUEST[$reqestParam]) ? $_REQUEST[$reqestParam] : 'not set';
$modx->log(modX::LOG_LEVEL_ERROR, 'Request to Uri "' . $requestUri . '" q="' . $identifier .'"');
}
break;
}
If you request the URL yourdomain.com/index or yourdomain.com/index/, what gets logged for “q” in the MODX error log?
Is it Request to Uri "/index" q="not set" or Request to Uri "/index" q="index"?
Thank you Harry - I get…
Request to Uri "/index" q="not set"
It looks the same on my test environment. Not sure if something could be changed in the Apache config to change this behaviour.
You could change the plugin code to something like this instead:
<?php
$eventName = $modx->event->name;
switch($eventName) {
case 'OnHandleRequest':
if ($modx->context->get('key') != "mgr") {
$requestUri = $_SERVER['REQUEST_URI'] ?? '';
$requestUri = strtok($requestUri, '?'); // Remove query string if existing
if (preg_match("#^/index/?$#i", $requestUri)) {
// Redirect to start page
$parameters = $modx->request->getParameters();
unset($parameters[$modx->getOption('request_param_alias')]);
$url = $modx->makeUrl($modx->getOption('site_start', null, 1), $modx->context->get('key'), $parameters, 'full');
$modx->sendRedirect($url, ['responseCode' => $_SERVER['SERVER_PROTOCOL'] . ' 301 Moved Permanently']);
}
}
break;
}
This should redirect request to domain.com/index and domain.com/index/ to the start page (domain.com).
Thanks Harry. It’s strange as it’s only just started being flagged up across a few sites. I’m a bit nervous about using a plugin as the sites do perform well in searches and I wonder if it’s just an advisory and Google will make its own mind up eventually. What’s your opinion?
I have no insight into Google. ![]()
Nothing has changed in MODX, so maybe just wait and see, as everything should still work the same as before.
Thanks Harry - it’s a strange one. I’ll see how many sites this pops up on and see if there’s a common thread