Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

301 Redirect for some pages and another one for all other pages



3:16 pm on May 29, 2013 (gmt 0)


I would appreciate any help trying to figure out how to set a a rule for a few specific pages and a general one for all the others.

My latest attempt failed (after a few hours trying to figure out)

Redirect 301 /oldpage1 http://example.com/whatever/
Redirect 301 /oldpage2 http://example.com/whatever/thispage.php

RewriteEngine on
RewriteRule (.*) http://example.com [L,R=301]

Thank you in advance.

[edited by: phranque at 12:26 pm (utc) on May 30, 2013]
[edit reason] use example.com please [/edit]


7:14 pm on May 29, 2013 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

Someone will come along shortly and change your URLs to "example.com" (see Forums charter and also format of post when you don't exemplify).

When you say "failed", you know what you mean but we don't. It can be anything from "crashed the server" to "had unintended effects" to "had no effect at all".

Never never never combine mod_alias (Redirect by that name) with mod_rewrite. You have no control over what order they'll execute in. On shared hosting mod_rewrite will generally happen first. But it isn't safe to make any assumptions, so use only one or the other.

In this case, simply configuring all the redirects as RewriteRules may be enough to solve the problem. Or, if it turns out that all rules will work in mod_alias, use that.


8:04 pm on May 29, 2013 (gmt 0)

Hi Lucy,

Sorry for the domain name, thank you for the information.

To be more precise, 'failing' means that all redirect are heading to "example.com", the two previous specific rules are not taken into account, but no crash. I understand that I must not mix mod_alias and mod_rewrite. I admit my weekness why rewrite rules, so complex. :-)


8:46 pm on May 29, 2013 (gmt 0)

...the two previous specific rules are not taken into account, but no crash.

This is almost certainly due to the execution order that Lucy described. Admittedly this part of Apache's behavior isn't at all obvious. Even though your code lists the two "oldpage" redirects first, they will nonetheless execute _after_ the rewrite redirect.

I also agree with Lucy's proposed solution. Due to this non-obvious execution order, it's probably better to use _only_ Redirect or _only_ RewriteRule. That way things will execute in an obvious top-down order.


8:58 pm on May 29, 2013 (gmt 0)

Do you have a sample that I can test using either method? No worries with results, I can backup easily if there are any issues. By the way, sorry with the last sentence of my last posting, please read "I admit my weakness with rewrite rules"... Thank you.


9:13 pm on May 29, 2013 (gmt 0)

For example, by changing:

RewriteRule (.*) http://newdomain [L,R=301] 


Redirect 301 / http://newdomain/


9:31 pm on May 29, 2013 (gmt 0)

Yes, only issue is that it's carrying the old path which leads to a 404 on new domain while it should go straight to newdomain root. The two only exceptions are the 2 oldpages redirect to a specific newdomain page.


9:52 pm on May 29, 2013 (gmt 0)

OK. In that case, perhaps...

RedirectMatch 301 (.*) http://newdomain/

Note that it's also an option to instead convert the other "oldpage" redirects to rewrite redirects.


10:04 pm on May 29, 2013 (gmt 0)

I could make it work using: RedirectMatch 301 ^/ [newdomain...] Does it look ok to you? It's working fine for the oldpages and .* to newdomain as well.


11:41 pm on May 29, 2013 (gmt 0)

Yup, that's totally fine. Perhaps even slightly better than my last post, since you don't actually need to capture the path, you just need a positive match.


8:07 am on May 30, 2013 (gmt 0)

Perfect, I'm proud! :-) Thank you very much to you Dideved and Lucy24.


12:27 pm on May 30, 2013 (gmt 0)

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

welcome to WebmasterWorld, lafronde!

Featured Threads

Hot Threads This Week

Hot Threads This Month