We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 31902
    • 342 Posts
    I'm having issues with duplicate content on the home page because it seems that index.php is being treated as a different page than www.sample.com/index.html.

    I have user friendly URL's turned on. Now, when I go to www.sample.com/index.html, it canonically goes to www.sample.com. That's good.

    However, I would like to have the "index.php" home page go to www.sample.com after I type: www.sample.com/index.php.

    Right now, when I type www.sample.com/index.php, it remains at that address. Is there a way to make it go to www.sample.com?

    MODx doesn't seem to like 301 redirects by way of an .htaccess file. I also tried to redirect index.php to www.sample.com by way of the Redirector component. Didn't work.

    My .htaccess file contains this:

    # Friendly URLs Part
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} .
    # Force all pages to go to www.sample.com for SEO
    RewriteCond %{HTTP_HOST} !^www\.sample\.com [NC]
    RewriteRule (.*) http://www.sample.com/$1 [R=301,L]
    # Friendly URLs
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
    # Additional Settings Follow
    ExpiresActive On
    ExpiresByType image/gif A2592000
    ExpiresByType image/jpeg A2592000
    ExpiresByType image/png A2592000
    BrowserMatch "MSIE" brokenvary=1
    BrowserMatch "Mozilla/4.[0-9]{2}" brokenvary=1
    BrowserMatch "Opera" !brokenvary
    SetEnvIf brokenvary 1 force-no-vary
    


    Any ideas? Thanks in advance.

    Running MODx Revo 2.2.6-pl
    Redirector 1.0.3
      • 40706
      • 128 Posts
      If you want that, write an redirect rule over the main modx rewrite condition like this one:

      ...
      RewriteRule (.*) http://www.sample.com/$1 [R=301,L]
      
      # URL redirects
      RewriteRule ^index\.php$ / [R=301]
      
      # Friendly URLs
      RewriteCond %{REQUEST_FILENAME} !-f
      ...
      
        • 31902
        • 342 Posts
        Thanks, Michael, however, it didn't work. I get redirect loop errors.

        Anyway, this is really stumping me. [ed. note: waizen last edited this post 11 years, 2 months ago.]
        • I don't think you can do that. The actual request has to be for index.php, and the rewrite is done by rewriting all not-found files to index.php with the actual filename appended = index.php?q=page.html

          So you can't prevent index.php from being used.
            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
            • 31902
            • 342 Posts
            Thanks, Susan for responding. If it cannot be changed, then how does one prevent index.php and domain.com/ from being flagged as duplicate content by search engines from a MODx site? [ed. note: waizen last edited this post 11 years, 2 months ago.]
              • 2396
              • 101 Posts
              I know this is an old thread but it is important, SEO wise.

              I had this problem and it appears to be fixed with the below code (redirects to the www version) as my .htaccess friendly URLs redirect. It should be pretty solid because I also have around 200 lines of custom 301 redirects and it all plays well together.

              RewriteEngine On
              
              RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php
              RewriteRule ^index\.php$ / [L,R=301]
              
              # Rewrite www.domain.com -> domain.com -- used with SEO Strict URLs plugin
              RewriteCond %{HTTP_HOST} .
              RewriteCond %{HTTP_HOST} !^www\.domain\.com\.au [NC]
              RewriteRule (.*) http://www.domain.com.au/$1 [R=301,L]
              #
              # or for the opposite domain.com -> www.domain.com use the following
              # DO NOT USE BOTH
              #
              # RewriteCond %{HTTP_HOST} .
              # RewriteCond %{HTTP_HOST} !^www\.example-domain-please-change\.com [NC]
              # RewriteRule (.*) http://example-domain-please-change.com/$1 [R=301,L]
               
              # The Friendly URLs part
              RewriteCond %{REQUEST_FILENAME} !-f
              RewriteCond %{REQUEST_FILENAME} !-d
              RewriteRule ^(.*)$ index.php?q=$1 [L,QSA,NC]
              

                • 31902
                • 342 Posts
                Quote from: atype at Jul 29, 2014, 02:24 AM
                I know this is an old thread but it is important, SEO wise...

                Wow, atype, here it is over nine months after you posted your reply and I finally see this (by accident since I was looking for the answer to this question, having forgotten I already asked it :-O ). I guess I didn't have "Email me new replies" box checked.

                So, I just tried your solution and it did work. Thank you!