3

Google Webmaster Tools shows a lot of duplicate content in the following pages:

  • www.example.com/example
  • www.example.com/example/

I do NOT offer two versions of any page on my website, when you type example.com/example you are REDIRECTED to example.com/example/. However, Webmaster Tools shows both versions of my page, considering it to be duplicate content.

How can I fix this?

  • This is not normal. I would not recommend a redirect per se' as in an .htaccess file. If you have Apache, you can add the mod_dir module documented here: httpd.apache.org/docs/2.4/mod/mod_dir.html I know there are similar options for IIS and Nginx. – closetnoc Aug 24 '15 at 18:12
  • Thanks for the reply, but I'm not quite sure how to do that. Could you be more specific, please? I have a wordpress website. – URL Issues Aug 24 '15 at 19:23
  • Is /example a filesystem directory? How are you redirecting? – MrWhite Aug 24 '15 at 22:29
  • /example is a subdirectory. My main domain is pointed to the root directory and /example is another wordpress in a subdirectory. That's what I have in htaccess: <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /example/ RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /example/index.php [L] </IfModule> – URL Issues Aug 25 '15 at 14:50
2

On an apache server with mod_rewrite installed, you can add this code to your httpd.conf (main apache configuration file) and restart apache gracefully.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} ^(.*)/$ [NC]
RewriteRule ^(.*)$ %1 [NC,R=301,L]

It will redirect all URL requests ending in a / to the same request without a / provided its not a file or folder.

  • The URLs already redirect just to one version of the page... I have this in htaccess: <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /example/ RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /example/index.php [L] </IfModule> – – URL Issues Aug 25 '15 at 14:54
0

I do not know WordPress at all. There may be an option for this. I would check the documentation.

You should not need to do a redirect. Apache will do this for you.

Otherwise, see if the /etc/apache2/mods-enabled/ directory has dir.conf and dir.load exist, then in your /etc/apache2/sites-enabled/ directory you should find a .conf file for your site. If you only see 000-default.conf, then this is it. If you see something like example.com.conf, then this is your conf file. Some installs do not have the various -enabled directories, then your configuration would be /etc/apache2/httpd.conf.

If your site is using httpd.conf, then you will see a line like...

LoadModule dir_module modules/mod_dir.so

... and make sure it is not commented out with a #. You would simply remove the # and restart Apache.

If you do have the -enabled directories and see the various files I mentioned above, check to see if the dir.conf and dir.load files exist within /etc/apache2/mods-enabled/. If not, I think you can simply copy them from /etc/apache2/mods-available/ to /etc/apache2/mods-enabled/ and restart Apache.

Test to see if this works by going to example.com/somedirectory (without the trailing slash). It should work. Generally nothing else is needed. But sometimes this needs to be turned on.

If that is the case, find your httpd.conf and place...

DirectorySlash On

... within the <IfModule dir_module> or within your /etc/apache2/mods-enabled/dir.conf file. You should not need to do this however. The default for DirectorySlash is On.

This is normally enabled so it has been a long time since I have had to do this. You may have to play around with this a bit, but it should at least resemble the instructions I gave.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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