Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

Possible Duplicate:
What is duplicate content and how can I avoid being penalized for it on my site?

I have a website with some sub domain folders and seomoz is picking them up as both duplicate content and duplicate page titles. In actual fact, its the same page i.e. www.example.com/subdomain/index.php is seen the same as www.example.com/subdomain/ I want to point everything to the later.

I'm sure this will be done in the htaccess file. I sorted it for the main site (home page) and everything works fine but when I tried copying the code and re jigging it for the subdomains, either nothing happened or the page went down.

share|improve this question
    
FYI, you can use canonical URLs to tell the search engines that the /subdomain/ and /subdomain/index.php are the same page and to use /subdomain/ as the primary URL. –  John Conde May 7 '11 at 13:44
add comment

marked as duplicate by danlefree Oct 14 '12 at 22:18

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer

This is a fairly common problem and John Conde's suggestion to use canonical URL's is a safe bet.

You may have other options, depending upon how comfortable you are with editing your server configuration and PHP scripts.

Apache mod_rewrite directive

Advantages: Does not require modifying your PHP application.

Disadvantages: Processing overhead for the rewrite engine on every request. (Note that the disk access overhead associated with enabling the AllowOverride directive for .htaccess support is typically greater than the modest processing overhead incurred by mod_rewrite)

The following mod_rewrite directives will permanently redirect users to the directory requested if index.php is appended:

RewriteEngine on
RewriteRule (.*)\/index\.php$ /$1/ [R=301,L]

PHP conditional

Advantages: Does not require use of mod_rewrite, processing overhead incurred only on PHP file requests.

Disadvantages: Requires editing PHP scripts and introduces potential for scripting errors. Requires knowledge of PHP troubleshooting should errors occur.

If your application consists of multiple files which all include the same heading file or template, you can add the following conditional block to the file before any HTML is printed or echoed: (calls to PHP's header() function will fail if any output has been sent to the user)

<?php
    $uri = strtok($_SERVER['REQUEST_URI'],'?');
    if ( 'index.php' == substr($uri, -9) )
    {
        $redirect_uri = ($_SERVER['HTTPS']) ? 'https://' : 'http://';
        $redirect_uri .= $_SERVER['HTTP_HOST'];
        $redirect_uri .= substr( $uri, 0, strlen($uri) - 9 );
        header( 'HTTP/1.1 301 Moved Permanently' );
        header( 'Location: ' . $redirect_uri );
    }
    unset($uri);
share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.