301 a whole site but also redirect specific pages

The site is an Opencart shopping cart of perhaps 100 pages; 4 of them valuable. I would like to 301 those four pages to particular page on a new site, and also 301 the whole site/all the other pages to the new site. Does it make sense to do this and if so how?

Many thanks.


Yes, read the tutorial linked in my signature. Then, if, after reading the coding examples, you’re still having problems, provide your sample code, your test URIs and their results and I’ll get you through this.




I haven’t written it yet as I don’t know who to do the the pages don’t require individual redirects. This is what I have planned so far:

RewriteEngine on

Redirect 301 /index.php?route=product/product&product_id=1 http://www.new.com/new1
Redirect 301 /index.php?route=product/product&product_id=2 http://www.new.com/new2
Redirect 301 /index.php?route=product/product&product_id=3 http://www.new.com/new3
Redirect 301 /index.php?route=product/product&product_id=4 http://www.new.com/new4


From others’ questions, Redirect does not examine the query string therefore your code, while a good attempt, won’t work.

The alternative is to use mod_rewrite which CAN examine the query string and use the value of a key in the redirection. An example, using YOUR coding above, would be:

RewriteEngine on
RewriteCond %{QUERY_STRING} product_id=(/d+)
RewriteRule ^index\\.php$ http://www.new.com/new%1

Of course, if the values of product_id are not digits or cannot be appended to new on the new server, my example code must change.



Thanks very much, dklynn. The URIs I gave aren’t far off the actual, but I didn’t realise it would be so complicated, so I ought to give you something more precise, thanks for bearing with me here.

http://www.old.com/index.php?route=product/product&product_id=49 >> http://www.new.com/[COLOR=“#FF0000”][B]item-aaa[/B][/COLOR]
http://www.old.com/index.php?route=product/product&product_id=50 >> http://www.new.com/[COLOR=“#FF0000”][B]item-bbb[/B][/COLOR]
http://www.old.com/index.php?route=product/product&product_id=51 >> http://www.new.com/[COLOR=“#FF0000”][B]item-ccc[/B][/COLOR]
http://www.old.com/index.php?route=product/product&product_id=52 >> http://www.new.com/[COLOR=“#FF0000”][B]item-ccc[/B][/COLOR]

Everything blue is the literal copy & paste from the old domain with only the domain name changed to old.com. The red in the new domain isn’t the actual copy and paste but it is the correct format in the sense that it is a hyphenated name with no numbers and no .html or .php at the end, as the Drupal cms has created an alias.

I would like to redirect is the home page

http://www.old.com >> http://www.new.com

In fact, I would also like to pass the whole site to the new one… there are dozens of other miscellaneous pages that can all point to the new site’s home page.

Thanks for any help.


I can see why you wouldn’t have shown the real redirections …

… because there is no way for mod_rewrite to map using your query string (route=product/product&product_id=49) to item-aaa. Like I tell people, I may be psycho but I’m not psychic! Same for Apache’s mod_rewrite.

Now that you’ve been “properly chastised,” you can make these redirections (hard-coded) so I’ll hope you don’t really have dozens. If you do have that many (AND access to the httpd.conf), you can use a RewriteMap. Yeah, I didn’t think the server belonged to you (because you’re moving) so there is a “poor man’s RewriteMap” which you can use: If you see your query string, redirect to a “handler file” which can read {THE_REQUEST} and have it lookup the redirection then use PHP to redirect to the new URL. Oh, yes, all this is in my signature’s tutorial.

As for your redirection from old.com to new.com, that’s a piece of cake (but I’ll refer you to the example section of the tutorial).