Forum Moderators: phranque

Message Too Old, No Replies

Redirecting index.php while using rewrite commands

Trying to avoid an infinite loop

         

macavity

6:58 pm on Jun 10, 2005 (gmt 0)

10+ Year Member



Hello all,

Can someone shed any light on the following for me? I've come across a couple of similar posts in the archives but I'm a bear of very little brain and can't quite figure out if what I'd like to do is possible.

The situation

My website uses a CMS running on Apache and Linux which offers access to the site's homepage through the following URLs

www.xyz.com
xyz.com
www.xyz.com/index.php

I have noted that each of these URLs has gathered a different page rank in Google and have read that multiple URLs of this nature, pointing to the same page, run the risk of diluting page rank over time by dividing the efficacy of back links to what is in reality a single page (for whatever PR is now worth) and also attracting a duplicate content penalty.

Assuming for the moment that these risks are real and worth taking steps to avoid, my understanding is that the best way to counter these problems is to use a permanent (301) redirect in the .htaccess file to redirect all these URLs to only one, usually www.xyz.com

The problem

Attempting to use a 301 redirect to do as suggested above results in a "redirection limit exceeded" error which I am guessing is related to my use of rewrite commands later in the .htaccess file of the following type:

RewriteRule page-name-1 index.php?name=xyz
RewriteRule page-name-2 index.php?name=Content&pa=showpage&pid=1

The solution

Is there one? Can I use a permanent redirect to address my homepage URL issues while at the same time using rewrites to provide more readable/memorable URLs for my other pages?

Any advice on the above would be very welcome. Thank you!

Kind regards,

Mac

jdMorgan

7:43 pm on Jun 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can use a permanent redirect, but it must be aware of the hostname being requested.

A redirect involves the browser. A 301 response is sent to the browser that means, "The resource you requested has moved. Ask for it again at the following URL." The URL you included in the redirect code is provided to the browser. The browser then issues an entirely new HTTP request using the provided URL.

Obviously, if your redirect code is unaware of the requested domain, then it will simply redirect again, and the result is what your are experiencing.

This recent thread [webmasterworld.com] discusses using mod_rewrite to construct a requested-domain-aware redirect.

Jim

macavity

10:18 pm on Jun 10, 2005 (gmt 0)

10+ Year Member



Jim,

Many thanks for your reply. Unfortunately I've read through the topic in question and have to admit I'm completely out of my depth here.

Just to clarify, what I tried before in my .htaccess file as far as the permanent redirect was concerned was the following:

redirect 301 /index.php$ [xyz.com...]

(which came before the rewrite commands listed previously)

Looking at the other thread I don't see any "redirect" commands. Am I right in thinking that the following (taken from the thread in question) is functionally equivalent?

RewriteCond %{HTTP_HOST} ^domain\.co\.uk
RewriteRule (.*) [domain.co.uk...] [R=301,L]

I see a reference to the host (HTTP_HOST) and the number 301 which I'm guessing means this is the type of structure you were referring to?

Apologies for my complete lack of knowledge. If you could just confirm that I'm on the right lines with the above then I'll go away and investigate things further. Many thanks in advance.

Mac

jdMorgan

3:12 am on Jun 11, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, that code is a requested-host-aware 301 redirect from non-www to www. You can reverse that if you like.

The point I was trying to make is that a Redirect directive can only be used if the two domain variants are hosted separately; Since Redirect cannot be made to act conditionally based on the requested domain, it will simply loop 'forever' if the two domains resolve to the same host (actually it redirects to itself until the maximum redirection limit of the browser or server is reached, whichever comes first).

Jim