Closed romainpoirier closed 2 years ago
Sounds like an issue with your routes in config/routes.php
, which is covered in the upgrade guide here.
Can you post the contents of that file?
That's what I thought, as this is from a very old Craft 2 website, not the most mature:
<?php
return array(
'/?404/?(.*)' => '404',
'/?(?P<slug>.+)/?(.*)' => '_routing',
'/?(.*)/(?P<slug>.+)/?(.*)' => '_routing',
);
But even after replacing this by an empty array()
, the same error is shown.
Those values need to be updated to template
rule arrays:
<?php
return [
'/?404/?(.*)' => ['template' => '404'],
'/?(?P<slug>.+)/?(.*)' => ['template' => '_routing'],
'/?(.*)/(?P<slug>.+)/?(.*)' => ['template' => '_routing'],
];
But even after replacing this by an empty
array()
, the same error is shown.
Hm not sure what to make of that. The stack trace definitely shows that it is due to a misconfigured route array. Maybe you forgot to save your changes, or PHP just hadn’t noticed that you had changed the file due to OPcache.
Thank you. I have edited the content with your uodated version, but unfortunately without any change.
I have also resave and reboot the server twice after modifying all of routing.php
to <?php return array();
but the same error is still returned for every page on front-end. Even if I empty the /templates
folder with a single very simple template.
From what I know, there's no caching enabled on my MAMP.
No further idea to investigate?
it’s config/routes.php
, not routing.php
. Was that a typo, or are you maybe editing the wrong file?
Sorry it was just a typo, I can confirm that the file is located at config/routes.php
using <?php return array();
.
Not really sure what to make of this, then. Can you zip up your whole project along with a database backup and send it into support@craftcms.com? We can look into it from there.
Done ✔. Thank you.
Thanks! Was able to reproduce with your site and it is indeed a Craft bug, caused by your 404
route defined in Settings → Routes. Turns out you’d get this error any time the first control panel-defined route had a numeric URI pattern. That doesn’t seem very far-fetched so I’m pretty surprised no one has run into this before.
It’s fixed now for the next release. To get the fix early, change your craftcms/cms
requirement in composer.json to "dev-develop as 3.7.26"
and run composer update
.
Thank you @brandonkelly. The UrlRule::pattern must be set
error is now over.
But I now get a preg_match(): Compilation failed: quantifier does not follow a repeatable item at offset 1
even with this as config/routes.php
:
<?php
return [
'/?404/?(.*)' => ['template' => '404'],
'/?(?P<slug>.+)/?(.*)' => ['template' => '_routing'],
'/?(.*)/(?P<slug>.+)/?(.*)' => ['template' => '_routing'],
];
Any idea why or if it's a related issue to what have been fixed?
@romainpoirier if a pattern starts with a slash as yours do, you need to escape it, otherwise PHP will think you are using /
as your regex delimiter.
That said, there are some other things going on:
<ParamName:RegExp>
). There are some exceptions (e.g. optional ?
matching)Named parameters in the pattern should be defined using the format (
<ParamName:RegExp>
) rather than as a regular expression subpattern((?P<ParamName>RegExp))
.
Have another look at the upgrade guide for URL rules, which covers this.
So, your patterns should look something like this :
'404/?<pathRemainder:.*>' => ['template' => '404'],
pathRemainder
will then be available in your template.
Craft 3.7.27 is out with that initial bug fix.
Description
I have followed the steps described in the documentation. Everything gone smooth, and seems to works as expected in the CP. However, I can't access any page on front-end, because of this error:
Any idea of what's going wrong? I didn't found any related issue.
Additional info