In my functions file, I have a function that re-writes the URL into the name of page or post from https://example.com/index.php?page=faq
into https://example.com/faq
.
Problem is, it's not working. If I use it, all pages and posts turns into this:
Not Found
The requested URL was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
This is the code I am using to re-write. Is the problem within this or what am I'm doing wrong? Using PHP 8.
function url($url) {
if (rewrite_url) {
$url = preg_replace('/\&(.*?)\=/', '/', str_replace(['index.php?page=', 'index.php'], '', $url));
}
return base_url . $url;
}