URL Structure Question
-
Hey folks,
I have a weird problem and currently no idea how to fix it. We have a lot of pages showing up as duplicates although they are the same page, the only difference is the url structure. They seem to show up like:
http://www.example.com/page/andhttp://www.example.com/pageWhat would I need to do to force the URLs into one format or the other to avoid having that one page counting as two? The same issue pops up with upper and lower case:
http://www.example.com/Pageandhttp://www.example.com/pageIs there any solution to this or would I need to forward them with 301s or similar?
Thanks,
Mike
-
I believe the easiest way would be to add or remove the trailing slash in your .htaccess file in the root directory.
Make sure you backup your .htaccess file before you edit it!
The below may work for you but I would guess someone more experience in this area could help more with the coding:
"
Use this code to your .htaccess file to remove trailing slashes:
#get rid of trailing slashes
RewriteCond %{HTTP_HOST} ^(www.)?turbocelica.lv$ [NC]
RewriteRule ^(.+)/$ http:/www.example.org/$1 [R=301,L]or use this code to ADD trailing slash to the end of each URL:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)([^/])$ http://www.example.org/$1$2/ [R=301,L]"
-
Hey Mike,
Opt is correct the .htaccess file is the way to go but I would first test this in a sandbox / development environment as messing with this file can bring your entire site down quickly if you get it wrong (and sometimes you think you have it right and there is a knock effect elsewhere).
Failing that you could always add rel canonical tags to your site which either use the trailing slash format or not. This may be easier to do depending on the CMS you are using.
-
What happens when you naviaget to these urls,
[http://www.example.com/page/](http://www.example.com/page/)and[http://www.example.com/page](http://www.example.com/page)do they resolve to one or the other, or do both render the page?The answer is to 301 to one or the other, and make sure you are not using both formats in your site.