PDA

View Full Version : RedirectMatch NOT WORKING


ralfb
02-11-2006, 11:50 AM
Hi,

I have created a .htaccess file with the following after reading post on this forum:

ErrorDocument 404 /404.shtml
RedirectMatch (.*)$ http://www.procurement.info$1

When entering the old domain name (prokudos.com) into the browser address bar, I can see that the browser's status bar is looking up procurement.info, however before the page loads, I get an error message that reads:

"Redirection limit for this URL exceeded. Unable to load the requested page. This may be due to cookies that are blocked.." I am getting the same error in Firefox, Netscape and IE, as well as Safari. Safari even states:

"Too many redirects occurred trying to open “http://www.procurement.info/”. This might occur if you open a page that is redirected to open another page which then is redirected to open the original page."

Can you please help me out, thanks,
Ralf

sheila
02-11-2006, 11:57 AM
Your Redirect expression matches on

(.*)$

which matches ANYTHING.

Including the URL you are trying to redirect to.

Imagine this scenario...

The URL http://www.procurement.info$1 is requested.
It matches (.*)$
It is redirected to http://www.procurement.info$1

The URL http://www.procurement.info$1 is requested.
It matches (.*)$
It is redirected to http://www.procurement.info$1

etc...

As you can see, this causes a loop.

You will need to be a bit more discerning in your match expression.

You might want to search these forums on
RedirectMatch

You will probably find at least a few more threads where these types of commands have been discussed, and may provide some insight in how to accomplish your task while avoiding the infinite loop situation...

ralfb
02-12-2006, 06:16 AM
Thanks for that, did some more research on the web. Now using below and that seems to do the trick:

RewriteEngine on

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


The first line turns the RewriteEngine on so the following code will work.

The second line is TRUE if the host is not www.procurement.info. The \ character is required to "escape" the . character. (The [NC] flag means to ignore case.)

The third line is TRUE if host is not an empty string.

The fourth line is executed if the previous two conditions return TRUE. This line says to redirect permanently to the fully qualified domain name (www.procurement.info). The L flag means this is the last rewrite directive, the "R=301" flag says to redirect to the rewritten URL permanently (HTTP response code 301).


Best,
Ralf

sheila
02-12-2006, 10:47 AM
Glad to hear you go that sorted out, and thanks for posting the follow-up. I especially like the line-by-line explanation. How nice! :noddy:

:yeah: