Welcome Guest, Not a member yet? Register   Sign In
Setting url suffix


in CI3 we could use url_suffix in the config. Where is this option in CI4?

CI4 does not have the option.

By the way, why do you need it?

(This post was last modified: 07-20-2022, 09:41 AM by groovebird.)

(07-04-2022, 05:41 PM)kenjis Wrote: By the way, why do you need it?

My Urls have the .html suffix and now it is missing, beacause CI3 generated it. In routes definiton now i have to add .html suffix in order to work

Thank you.

One solution:

Or you could customize Router to support url suffix.

(07-20-2022, 02:40 PM)kenjis Wrote: Or you could customize Router to support url suffix.

Is there any documentation how to customize the router or can you give me a tip please?

See Creating Core System Classes — CodeIgniter 4.2.1 documentation

This is a kludge of course (Codeigniter 4 should support this natively in my opinion) but you can do something like this.  The regular expression addition strips off any .html extension before continuing on processing the route.  This allows requests to work with or without ".html" as the file extension present in the original request. 


Line 173:

        // Decode URL-encoded string
        $uri = urldecode($uri);
        // kludge to work around .html extension on existing links
        $uri = preg_replace('/(.*)\.html(\?.*)?$/','\1\2',$uri);

Theme © iAndrew 2016 - Forum software by © MyBB