We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26931
    • 2,314 Posts
    Hi there,

    i thought it would be handy to have the ability to redirect all requests from domain.com to -> www.domain.com without the use of .htaccess

    ...because some hosting companies don’t offer .htaccess feature for their standard webpacks to run MODx on, so you would have to upgrade to a more expensive one to get that feature. wordpress for example has this redirect feature built-in (that’s how i actually got the idea for that plugin)

    this plugin could be useful especially for people using the plugin DirectResize, which will only let you use either domain.com or www.domain.com, so pictures that get cached the first time on domain.com won’t show up for the request on www.domain.com, so this plugin could help with that...and for seo reasons as well of course.

    sure the best solution would be .htaccess, so this plugin is not an substitute at all...just quick fix smiley maybe this should be a built-in feature anyways, what do you think?

    well, since i’m not a programmer, i would be very thankful if someone could have a look at it and tell me if this is nonsense, or if this could be used on a live site ( i tested it, and it seems to work...)

    so here’s the code (it’s tinyyyyy):

    create a plugin, call it "PHPredirect" (or whatever), fill in the code:
    $site = "domain.com";
    if(strpos($_SERVER['HTTP_HOST'], "www.") !== 0){
        header("Location: http://www." . $site . $_SERVER['REQUEST_URI']);
    }

    change domain.com to your domain-name, and check in SystemEvents -> OnWebPagePrerender

    that’s it, now all requests go to www.domain.com

    cheers, jan