We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10226
    • 412 Posts
    lets say a user comes to www.modxsite.foo and every link from there out is www. - but on the same site if they just enter modxsite.foo every link from then out will not have a www.

    Right now I use apache directives to strip off the www. Is there something that can do this? I have never run into this, but I have one site that is needing this type of setup.

    Thanks!
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      The usual way to deal with this is with .htaccess rewrite rules.
      # Rewrite domain.com -> www.domain.com -- used with SEO Strict URLs plugin
      #RewriteCond %{HTTP_HOST} .
      #RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
      #RewriteRule (.*) http://www.example.com/$1 [R=301,L]
      
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 10226
        • 412 Posts
        Thanks Susan... I tried adding those in but they did not go over so well. Also I think my point might have been missed. I can force www or no www, but I want to make the links persistent based on the initial landing. so if they hit www. all links will have the www - if no www, stick to no www.

        Here is my current conf in apache for the host, we need to offer https on certain pages, so there is another thing to get around.

        <virtualhost *:80>
        DocumentRoot "/var/www/somesite.com/"
        <Directory "/var/www/somesite.com/">
        allow from all
        Options FollowSymLinks Indexes
        AllowOverride all
        DirectoryIndex index.php
        </Directory>
        RewriteEngine On
        RewriteRule ^/?secure/(.*) https://%{SERVER_NAME}/secure/$1 [R,L]
        RewriteRule ^/?signup/(.*) https://%{SERVER_NAME}/signup/$1 [R,L]
        ServerName somesite.com
        CustomLog     /var/log/apache2/somesite.com-access.log combined
        ErrorLog      /var/log/apache2/somesite.com-error.log
        LogLevel warn
        </VirtualHost>
        
        <virtualhost *:443>
        DocumentRoot "/var/www/somesite.com/"
        <Directory "/var/www/somesite.com/">
        allow from all
        Options FollowSymLinks Indexes
        AllowOverride all
        DirectoryIndex index.php
        </Directory>
        RewriteEngine On
        RewriteMap  lc int:tolower
        RewriteCond %{REQUEST_URI} [A-Z]
        RewriteCond %{REQUEST_URI} !^/cartoweb3
        RewriteCond %{REQUEST_URI} !^/tmp
        RewriteCond %{REQUEST_URI} !^/ms_tmp
        RewriteRule (.*) ${lc:$1} [R=301,L]
        ServerName somesite.com
        CustomLog     /var/log/apache2/somesite.com-access.log combined
        ErrorLog      /var/log/apache2/somesite.com-error.log
        LogLevel warn
        SSLEngine on
        SSLCertificateFile /etc/apache2/ssl/somesite.com.crt
        SSLCertificateKeyFile /etc/apache2/ssl/www.somesite.com.key
        SSLCertificateChainFile /etc/apache2/ssl/gd_bundle.crt
        </VirtualHost>
        


        and the .htaccess

        RewriteEngine On
        RewriteBase /
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ index.php?q=$1 [L,QSA,NC]
        FileETag none
        AddType text/x-component .htc
        php_flag register_globals Off
        php_flag zlib.output_compression On
        php_value zlib.output_compression_level 9
        BrowserMatch ^Mozilla/4 gzip-only-text/html
        BrowserMatch ^Mozilla/4\.0[678] no-gzip
        BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
        SetOutputFilter DEFLATE
        SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ \
            no-gzip dont-vary
        SetEnvIfNoCase Request_URI \
            \.(?:exe|t?gz|zip|bz2|sit|rar)$ \
            no-gzip dont-vary
        SetEnvIfNoCase Request_URI \.pdf$ no-gzip dont-vary
        ErrorDocument 403 /
        
        


        We are also using transalias if that matters
          • 22840
          • 1,572 Posts
          No Idea how to achieve it but if you do do that then Google is going to pick it up as 2 sites and penalize you for duplicate content undecided
            • 10226
            • 412 Posts
            actually, google doesn’t care about that, but anyway removing the base href solves this issue, but breaks links in child folders - it will append the child to the same child making a bad link and returning you to the index page, but preserve the bad url...

            This also breaks images not in the root dir.

            possibly some extended rewrite rules can fix this, but I am horrible with those. - we only have one subfolder / child with articles and don’t plan on adding any more anytime soon so possibly some very explicit rules could work. So if there are any rewrite masters out there...

            Thanks All!
              • 22840
              • 1,572 Posts
              actually, google doesn’t care about that,

              I disagree and as many SEO experts will tell you they either have the www or the none www but not both, but hey if there all wrong I will accept it wink
                • 32674
                • 101 Posts
                  • 10226
                  • 412 Posts
                  Thanks for the info! still need to fix my original issue though smiley

                  Thanks!
                    • 32674
                    • 101 Posts
                    Quote from: fruitwerks at May 24, 2010, 03:20 PM

                    Thanks for the info! still need to fix my original issue though smiley

                    Thanks!
                    Your issue is not particularly specific to modx, you basically want a correctly working htaccess file. Im on IIS and useless to ya. wink

                    I’d take your rewrite rule issues over to webmasterworld.com, there are amazing guys helping out -- Tedster & JDM, both great mods there, come to mind with htaccess, regex and rewrite rules-- this forum to be specific: http://www.webmasterworld.com/apache/

                    however, be prepared to fight on your stance that you want both www and non-www available. They are mostly in the ’one way or the other’ camp there, and will probably grill ya pretty well about why you would want to do that.
                      • 10226
                      • 412 Posts
                      Thanks - I was chatting with the httpd elders on freenode and they think it is ’silly’ - I will head over to webmasterworld and see what happens. I’ll update this post when I get a solution.

                      In the meantime, if anyone knows lol..

                      Thanks All!