Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2008-03-28 16:46:58

alannie
Member
From: Minnesota, USA
Registered: 2005-09-15
Posts: 150

Trailing slash issue in Google - how to redirect?

Hello,

In the Google Analytics reports for one of my TXP installations, some pages are showing up as two separate pages, one with a trailing slash and one without.

Example:

/section/title

vs.

/section/title/

I think this may have happened because some links were mistakenly coded in with a trailing slash. I’ve since corrected this but the trailing slash URLs are still indexed in Google. Duplicate pages in Google’s index are bad, not to mention the messy analytics, so I’d like to address this with a 301 redirect from slash to non-slash.

Can anyone recommend how to do this in my .htaccess file? I already have a non-www to www redirect, and I can’t seem to get the two to play nice together. Here’s what I have for the www redirect:

RewriteCond %{HTTP_HOST} ^mydomain\.com$ [NC]
RewriteRule (.*) http://www.mydomain.com/$1 [L,R=301]

Offline

#2 2008-03-28 18:23:32

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: Trailing slash issue in Google - how to redirect?

Perhaps something like this:

RewriteCond %{REQUEST_URI} ^/[^/]+/[^/]+/$
RewriteRule (.*)/ http://www.mydomain.com/$1 [L,R=301]

Offline

#3 2008-03-28 18:38:02

alannie
Member
From: Minnesota, USA
Registered: 2005-09-15
Posts: 150

Re: Trailing slash issue in Google - how to redirect?

Worked like a charm, thank you Ruud!!

Offline

#4 2008-04-01 14:57:55

alannie
Member
From: Minnesota, USA
Registered: 2005-09-15
Posts: 150

Re: Trailing slash issue in Google - how to redirect?

I just discovered an issue; these rules appear to cause a looping redirection when an agent is attempting to request a static sub-sub-directory. For example:

  1. http://www.mydomain.com/folder/subfolder/ redirects to …
  2. http://www.mydomain.com/folder/subfolder which the server then redirects back to …
  3. http://www.mydomain.com/folder/subfolder/ which once again redirects to …
  4. http://www.mydomain.com/folder/subfolder and so on …

Any thoughts on how to prevent this?

Offline

Board footer

Powered by FluxBB