Forum Topic: Remove trailing slash creates loop

Forum: .htaccess Forum : Redirecting • Posted by Jeroen • Updated:

Hi Jeff,

I had a website with permalinks /%postname%/ and I changed it into /%postname%.

I also added RedirectMatch 301 ^(.*)/$ /$1 to redirect the urls coming from other websites. Well, I thought, because this line creates a loop.

When I remove the slash in the permalinks, I have to add a 301 redirect rule right? Or can I do without? Also concerning the duplicate content issue?

And what is wrong with my redirectmatch line? Why does it create a loop? I thought I had it this time...

Thanks again.

Jeroen

16 Replies to “Remove trailing slash creates loop”

Jeff Starr
Posted by Jeff Starr

Hi Jeroen,

WordPress automatically appends a trailing slash to URLs, so this may prove difficult to accomplish with .htaccess. But then again, I've not tried to remove the trailing slash via the actual permalink settings.. are you able to get WordPress to not add any trailing slash? If so, you may not need to include a redirect, as WP should do it automatically..

Posted by Jeroen •

Hi Jeff,

Yes, WordPress removes the trailing slash when I use /%postname%.

I'm just worried that I get duplicate content when I don't use a 301, but then again, when I test using an external link with trailing slash, the trailing slash is removed automatically.

Maybe I can find back in the logs whether WordPress redirects it?

Thanks Jeff.

Jeff Starr
Posted by Jeff Starr

Yes WP should be redirecting to whatever permalink format you are using. There should be no need for .htaccess in this case, but as you suggest keeping an eye on your access logs for awhile is a good idea.

Posted by Jeroen •

Just confirmed that WordPress did a 301 indeed!

Good to know. Solved!

Thanks Jeff.

Posted by Jeroen •

So, WordPress does redirect, but in Webmastertools the duplicate contents start showing up. Hope Google will figure out soon that I have removed the trailing slash...

Jeff Starr
Posted by Jeff Starr

What are some examples of the URLs that are showing up in Webmaster Tools as duplicate content? (replace the domain name with example.com if needed)

Posted by Jeroen •

These are the ones on the Duplicate title tags page on WebmasterTools

http://example.com/semua/resep/page/7/ | http://example.com/semua/resep/page/7
http://example.com/nasi-goreng-hijau/ | http://example.com/nasi-goreng-hijau
http://example.com/semua/hidangan-sehari-hari/page/10/ | http://example.com/semua/hidangan-sehari-hari/page/10
http://example.com/semua/hidangan-sehari-hari/page/9/ | http://example.com/semua/hidangan-sehari-hari/page/9
http://example.com/semua/resep/page/6/ | http://example.com/semua/resep/page/6
http://example.com/semua/resep/page/16/ | http://example.com/semua/resep/page/16
http://example.com/cookies-cokelat/ | http://example.com/cookies-cokelat
http://example.com/semua/hidangan-sehari-hari/page/6/ | http://example.com/semua/hidangan-sehari-hari/page/6
http://example.com/pudding-mocca-kelapa/ | http://example.com/pudding-mocca-kelapa
http://example.com/semua/resep/page/17/ | http://example.com/semua/resep/page/17
http://example.com/semua/hidangan-sehari-hari/page/8/ | http://example.com/semua/hidangan-sehari-hari/page/8
http://example.com/semua/boncabe/page/7/ | http://example.com/semua/boncabe/page/7
http://example.com/chicken-katsu-kobe/ | http://example.com/chicken-katsu-kobe
http://example.com/sate-bumbu-kelapa/ | http://example.com/sate-bumbu-kelapa
http://example.com/semua/boncabe/page/11/ | http://example.com/semua/boncabe/page/11
http://example.com/semua/boncabe/page/3/ | http://example.com/semua/boncabe/page/3
http://example.com/semua/hidangan-sehari-hari/page/4/ | http://example.com/semua/hidangan-sehari-hari/page/4
http://example.com/semua/buka-puasa/page/2/ | http://example.com/semua/buka-puasa/page/2
http://example.com/semua/boncabe/page/5/ | http://example.com/semua/boncabe/page/5
http://example.com/macaroni-saus-opor/ | http://example.com/macaroni-saus-opor
http://example.com/semua/boncabe/page/2/ | http://example.com/semua/boncabe/page/2
http://example.com/semua/hidangan-sehari-hari/page/11/ | http://example.com/semua/hidangan-sehari-hari/page/11
http://example.com/semua/boncabe/page/10/ | http://example.com/semua/boncabe/page/10

Thanks

Jeff Starr
Posted by Jeff Starr

Wow, yeah that shouldn't be happening with WP.. what happens when you try to access any of the URLs without a trailing slash? Also, check the date that Google detected the duplicates -- it could be that googlebot crawled your site before you removed the conflicting .htaccess rules.

Posted by Jeroen •

With or without trailing slash, the page opens at the url without the trailing slash. So the redirection is done right. It looks like (hopefully only) these pages were crawled when I was struggling with the htaccess rules.

Since the redirection is happening, it's just a matter of time before the urls with trailing slash (=duplicate content) will dissapear from the webmastertools, right?

Thanks again, Jeff, for looking into the matter.

Jeff Starr
Posted by Jeff Starr

Yes I think that's what's happening, but keep a close eye on it until things start looking normal. It may take awhile for google to "forget" about those duplicate URLs, but they definitely shouldn't be finding any new ones.

My pleasure to help, Jeroen - have a great week ahead.

Posted by Jeroen •

Duplicate content 294 and counting...

Another disadvantage of removing the trailing slash is the stats in Analytics. Getting duplicate links there as well, one with index.php and the other one with / only.

Maybe not such a good move to remove the slash, but until now I have not yet seen a drop in visitors or avg. page position in Google.

After some months I'll probably laugh about it ;)

Jeff Starr
Posted by Jeff Starr

One thing that's important to keep in mind is that, even if your site doesn't serve any duplicate content via slashed and slashless URLs, the search engines may encounter either type of URL while crawling around the Web. So for example, if I changed all of my URLs at Perishable Press to remove the trailing slash, there would still be lots of links around the Web that point to my content using the old slashed URL format. As Google et al discover such URLs, they are reported via Webmaster Tools, Analytics, etc. So your site may be fine in terms of duplicate content, but the rest of the Web will take some time to adjust accordingly. Either way, just an FYI, and also it's good to hear that there hasn't been a drop in visitors :)

Posted by Jeroen •

Just for the record, duplicate content is now at 62 so it looks like Google is learning fast enough.

Jeff Starr
Posted by Jeff Starr

Ahh that's great news.. thanks for keeping us posted :)

Posted by Jeroen •

Yeah, it looks like things are going to be fixed soon. 18 left...

Posted by Jeroen •

And no more duplicate content anymore... So things are fixed in about 3 weeks. Faster than I expected.

Case closed!