Forum Moderators: phranque

Message Too Old, No Replies

Redirect and rewrite help

         

madk

3:24 pm on May 1, 2007 (gmt 0)

10+ Year Member



I need a small bit of help trying to redirect after doing a rewrite. I have 2 rewrites rules; one that handles single page articles and one that handles multiple pages. I just want to make sure Google doesn't index the same pages because they will have identical content.

Example:

www.mydomain.com/post/###/1
needs to redirect to:
www.mydomain.com/post/###

Here is what I have so far that handles the rewrites:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^post/([0-9]+)/$ view-article.php?id=$1
RewriteRule ^post/([0-9]+)$ post/$1/ [R]

RewriteRule ^post/([0-9]+)/([0-9]+)/$ view-article-page.php?id=$1&p=$2
RewriteRule ^post/([0-9]+)/([0-9]+)$ post/$1/$2/ [R]
</IfModule>

Any help would be greatly appreciated!

g1smd

11:14 pm on May 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



One thing that needs to be avoided as far as the redirect side goes:

redirection chains

You need to get from the requested URL to the final URL in just one step.

jdMorgan

2:05 am on May 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




RewriteEngine On
RewriteBase /
#
# If search engine request, redirect page-numbered request (with or without trailing slash) to article-only URL
RewriteCond %{HTTP_USER_AGENT} Googlebot¦Slurp¦msnbot¦Teoma [NC]
RewriteRule ^post/([0-9]+)/([0-9]+)/?$ http://www.example.com/$1/ [R=301,L]
#
# Redirect to fix missing trailing slashes for "post" requests at any "depth"
RewriteRule ^post/(([0-9]+/)*[0-9]+)$ http://www.example.com/post/$1/ [R=301,L]
#
# Redirect to fix requests for non-canonical domain name
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
#
# Internally rewrite static URLs to view-article script
RewriteRule ^post/([0-9]+)/$ view-article.php?id=$1
RewriteRule ^post/([0-9]+)/([0-9]+)/$ view-article-page.php?id=$1&p=$2

I'd recommend that you reproduce the "If search engine" logic above in your script, to avoid presenting them with "page-in-article" links that will always be redirected. That's "bad form" and wastes both of your time and bandwidth...

Replace the broken pipe "¦" characters above with solid pipe characters before use; Posting on this forum modifies the pipe characters.

Jim