We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27310
    • 18 Posts
    I’ve found a new version for redicting a www-URL to a no-www-URL:

    RewriteCond %{HTTP_HOST} ^www.(.+)$ [NC]
    RewriteRule (.*) http://%1/$1 [R=301,L]

    The version you use is:
    #RewriteCond %{HTTP_HOST} .
    #RewriteCond %{HTTP_HOST} !^example-domain-please-change\.com [NC]
    #RewriteRule (.*) http://example-domain-please-change.com/$1 [R=301,L]

    In my Version you haven’t to change anything to get it running ... wink

    I think you can try it for the no-www-URL to www-URL like this:
    RewriteCond %{HTTP_HOST} !^www.(.+)$ [NC]
    RewriteRule (.*) http://www.%1/$1 [R=301,L]
    But I don’t know if it is running ...

    Inspirated by:
    http://fplanque.com/dev/http-ssl/www-domain-canonical-urls-mod_rewrite
      • 25663 MODX Staff
      • 12,272 Posts
      Very interesting; thanks for sharing. Any mod_rewrite gurus out there able to confirm this won’t cause issues with FURLs or pages with parameters in the query strings?
        Ryan Thrash, MODX Co-Founder
        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
        • 27310
        • 18 Posts
        I’ve running this combination on several Servers:

        /.htaccess
        RewriteEngine On
        
        RewriteCond %{HTTP_HOST}   ^www.(.+)$ [NC]
        RewriteRule (.*)         http://%1/$1 [R=301,L]
        
        RewriteRule ^$ /cms [R=301,L] 


        /cms/.htaccess (Directory of ModX)
        RewriteEngine On
        
        RewriteCond %{HTTP_HOST}   ^www.(.+)$ [NC]
        RewriteRule (.*)         http://%1/$1 [R=301,L]


        1. Windows Server 2003 --> IIS-Server (ISAPI_Rewrite)
        2. Apache (Mod_Rewrite)
        3. Apache 2.0 (Mod_Rewrite)

        It deletes the WWW if it is set and route all Site-querys in the CMS-directory ...

        For ISAPI_Rewrite I have to rename the ".htaccess" into "_htaccess" ...

        -> It works perfect on all this servers I’ve tried it ! laugh laugh