Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Simple Mod Rewrite Question

Redirecting all URL to main domain



11:54 pm on May 25, 2003 (gmt 0)

10+ Year Member


What Im trying to do is I have a client who has several domain names all with the same content. Knowing google will hate this I want to redirect all the domains to the same (main) domain.

I thought about using a 302 redirect to do this but some other sites have already linked to one of the non-main URL's in the form:




but I want either one of those to be redirected to:

Hope that made some sense, sorry if it didnt!
Thanks so much for the help!


12:33 am on May 26, 2003 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member


Try searching using WebmasterWorld site search (link at top of page) for "301 domain redirect" plus your server name, e.g. Apache, IIS, etc. We've had many threads on this that will help you to define and narrow - or even answer - your question. But the methods available all depend on your server type.



1:33 am on May 26, 2003 (gmt 0)

10+ Year Member


I have already done just that. a 301 redirect will not suffice for my problem since I need the query string to be maintained. If I did a 301 I would just have to redirect all traffic from some-widgets.com/querystring to www.widgets.com with no query string.


2:08 am on May 26, 2003 (gmt 0)

10+ Year Member

Oh I am on Apache/Linux if that helps.

I did some reading and some said that a 301 redirect would keep the query string but I tested it and it didnt seem to.

It would the page so if I had it redirect from www.some-widgets.com/about.html it would in fact take me to www.widgets.com/about.html

but if I had www.some-widgets.com/index.php?widget=13132
it would just take me to www.widgets.com/index.php

Maybe I did something wrong but dont see how...
Let me know please!



2:42 am on May 26, 2003 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

Do you have access to mod_rewrite?
If so, do you have httpd.conf or .htaccess priveleges?

Using mod_rewrite, you can preserve the query string.

In .htaccess, using:

RewriteCond %{HTTP_HOST} !^www\.maindomain\.com
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^(.*)$ http://www.maindomain.com/$1?%1 [R=301,L]

will preserve both the requested page and the query string through the use of backreferences $1 and %1, and redirect requests to any domain other than www.maindomain.com to www.maindomain.com. As long as the domains in the first and last line match - allowing for the regex syntax requirement of escaping periods in the RewriteCond - this will work.

If your domains are hosted on separate virtual servers, the same thing will work, but you can/should delete the first RewriteCond.

Ref: Introduction to mod_rewrite [webmasterworld.com]



Featured Threads

Hot Threads This Week

Hot Threads This Month