Forum Moderators: phranque

Message Too Old, No Replies

multiple page redirects

         

Excalibur

5:48 pm on Feb 13, 2010 (gmt 0)

10+ Year Member



Hello,

I've been trying to use "Redirect 301" to redirect a multiple set of pages, but it seems that regexp doesn't work with that (at least from what I tried).
Is it possible to use one line to redirect
/blah & /balh/ & /blah/<whatever comes here> or at least /blah<whatever comes here whether or not prefixes with a forward slash> to a new page?
Redirect 301 /blah [mysite.com...]

Additionally, is there a way to make %{HTTP_HOST} parse within that line?


Regards,

jdMorgan

6:11 pm on Feb 13, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Loose examples lead to loose code.

Assuming that you want
/blah<anything or nothing>
and
/balh<anything or nothing>
to both redirect to the same destination URL, then

RedirectMatch ^/(blah|balh) http://www.example.com/newpage.php

should accomplish that.

> Additionally, is there a way to make %{HTTP_HOST} parse within that line?

This question makes no sense to me. Compilers and interpreters "parse" (take apart, analyze, and ascribe meaning to) code and command lines, but variables don't "parse within lines." What do you want to do with the %{HTTP_HOST} variable here?

Jim

Excalibur

7:14 pm on Feb 13, 2010 (gmt 0)

10+ Year Member



Jim,

I'm sorry if I didn't make sense.
/blah<anything or nothing> http://www.example.com/newpage1.php
/blah2<anything or nothing> http://www.example.com/newpage2.php
/blah3<anything or nothing> http://www.example.com/newpage2.php

^^ This is what I'm trying to do, yes.
As for %{HTTP_HOST}, I was trying to use it instead of www.example.com -> /blah<anything or nothing> [%{HTTP_HOST}...] <-

So, RedirectMatch ^/(blah) http://www.example.com/newpage1.php should do the trick?

jdMorgan

7:39 pm on Feb 13, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you're only concerned with the one "/blah" directory, then you don't need the parentheses.

If you wish to use %{HTTP_HOST} in the destination URL, you'll need to use mod_rewrite as opposed to mod_alias. However, this leaves the possibility that you may be redirecting to a non-canonical domain, so I'd suggest you use a preceding RewriteCond (and RewriteRule, if required) to force canonicalization of the hostname, put it into a "user" variable, and then back-reference that variable instead of the raw %{HTTP_HOST}.

The goals are to avoid redirecting to a non-canonical hostname, and to avoid chained/stacked/multiple redirects if the obsolete URL-paths are requested from a non-canonical host.

Jim

Excalibur

7:49 pm on Feb 13, 2010 (gmt 0)

10+ Year Member



Makes sense, thanks a lot :)