Forum Moderators: phranque

Message Too Old, No Replies

301 RedirectPermanent inconsistent?

         

broniusm

9:32 pm on Sep 28, 2005 (gmt 0)

10+ Year Member



I have inherited mngt of a site with a bunch of inbound, dead links. These pages are now subsets of external websites. To correct this, I have set up 301s for cases found in my error log.

I manage domain1.org and wish to pass on links to domain2.org and domain3.org appropriately.

A subset of my .htaccess has the following lines:

RedirectPermanent /health/environment.htm [domain2.org...]
RedirectPermanent /health/healthed.htm [domain2.org...]
RedirectPermanent /health/ [domain2.org...]

RedirectPermanent /emermgmt/emergencyplan.htm [domain3.org...]
RedirectPermanent /emermgmt/ [domain3.org...]

So when I make the call:
[domain1.org...]
my browser instead fetches:
[domain2.org...]

This principle works for the case of /health/ above, however, the same principle does not work for /emermgmt/. Instead of getting [domain3.org...] I get a 404 as [domain1.org...]

What might I be doing wrong?

jdMorgan

10:03 pm on Sep 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There's nothing obviuosly-wrong with your code. Are you sure that /emermgmt/ is not aliased or rewritten to a different directory-path by httpd.conf before your .htaccess can be invoked? The .htaccess code must be in a directory path between server root and the actual (previous) location of the /emermgmt/ files in order to work for this case.

Jim

broniusm

10:43 pm on Sep 28, 2005 (gmt 0)

10+ Year Member



jim- you really stay busy here!

..and you've hit it! My first implementation of redirects, which hit only /health by creating a physical subdirectory (/health) with a php redirect, was confusing me. My /health/index.php contained:


header("HTTP/1.0 301 Moved Permanently");
header("Location: http://www.domain2.org/");

The proper solution to handle both cases (/health and /health/) in my .htaccess is to graduate from RedirectPermanent in favor of RedirectMatch which supports regular expression. The following seems to work:


RedirectMatch 301 /health/?$ http://www.domain2.org/
RedirectMatch 301 /emermgmt/?$ http://www.domain3.org/

thanks!
-bronius

jdMorgan

10:53 pm on Sep 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Or even:

RedirectMatch 301 /(health¦emermgmt)/?$ http://www.domain2.org/

to compress both directives into one.

If you've got regex, might as well use it! :)

(Change the broken pipe "¦" character to a solid pipe before use. Posting on this forum modifies them.)

Jim

broniusm

12:26 am on Sep 29, 2005 (gmt 0)

10+ Year Member



hmm.. I like it-- and I can use that in other similar redirects on my site. However, in this case I've got to split redirects b/c the end targets are different sites' roots.

thanks for the tips and ueber-tips