Php class for url generator
You are on the right track, but there is some hidden complexity and repetition:

if ($this-&gt;rewrite == 1) {
    // ...
} else {
    // ...
}


The if statement above is peppered all throughout your code. You actually have a need one base class Url and two child classes that specialized in the different routing strategies. First, you'll want the Url class to be abstract, and specify all the methods that return URLs to be abstract as well. The one thing both routing strategies share in common is the domain name, which should be a private field with a protected getter to enforce encapsulation.

Lastly, you see a static method called create which chooses which concrete instance to return based on environmental variables.

abstract class Url {
    private $domain;

    public function __construct($domain) {
        $this-&gt;domain = $domain;
    }

    public abstract function home();
    public abstract function page($page);
    public abstract function manufacter($slug);
    public abstract function product($slug, $manufacter);
    public abstract function category($slug);

    protected function getDomain() {
        return $this-&gt;domain;
    }

    public static function create(): Url {
        if (SITE_REWRITE) {
            return new SearchEngineFriendlyUrl(SITE_URL);
        }

        return new PhpFileUrl(SITE_URL);
    }
}


Now you need one concrete class for each routing strategy:

class PhpFileUrl extends Url {
    public function home() {
        // ...
    }

    public function page($page) {
        // ...
    }

    public function manufacter($slug) {
        // ...
    }

    public function product($slug, $manufacter) {
        // ...
    }

    public function category($slug) {
        // ...
    }
}

class SearchEngineFriendlyUrl extends Url {
    public function home() {
        // ...
    }

    public function page($page) {
        // ...
    }

    public function manufacter($slug) {
        // ...
    }

    public function product($slug, $manufacter) {
        // ...
    }

    public function category($slug) {
        // ...
    }
}


Once you have this, you no longer need IF statements anywhere:

class PhpFileUrl extends Url {
    public function page($page) {
        return $this-&gt;getDomain() . '/' . $page . '.php';
    }
}

class SearchEngineFriendlyUrl extends Url {
    public function page($page) {
        return $this-&gt;getDomain() . '/' . $page . '.html';
    }
}


Each class becomes very clean and easy to understand. Furthermore, if your SEO friendly URLs change, you need only change the one class without affecting the other, which reduces your testing effort.

Remember that every branch in your code (think if statement and switchs) is another path to failure, and therefore another path you must test... in each method the branch exists.

Now, using this is just as easy as before, but gives you a more maintainable solution:

$url = Url::create();

echo $url-&gt;page('about');