Olddomain to Newdomain Redirect

Using a single web hosting account to host multiple sites

Olddomain to Newdomain Redirect

Postby StupidScript » Tue Nov 21, 2006 12:22 pm

I've been reading lots of forum entries and trying lots of syntax variations after starting with the basic example given in the Apache mod_rewrite docs, however I simply cannot get all requests to my old domain to redirect to the new domain. Here is some (perhaps) useful info from (a) my httpd.conf file, (b) my RewriteLog after an attempt and (c) the browser errors. Thanks for any help with this. As with every other troubled poster in these forums, it's driving me NUTS! ;)

Apache/1.3.27 running on RedHat v.7.2

==httpd.conf Entries of Interest:==
...
DocumentRoot /usr/local/apache/sites/newdomain
UseCanonicalName On
NameVirtualHost *
ServerName newdomain.com
...
<VirtualHost *>
ServerName www.olddomain.com
ServerAlias olddomain.com *.olddomain.com
ServerAdmin me@olddomain.com
DocumentRoot /usr/local/apache/sites/olddomain
ErrorDocument 404 http://www.olddomain.com/
ErrorLog logs/error_old.log
Options +FollowSymLinks
RewriteLog /var/log/mod_rewrite.log
RewriteLogLevel 5
RewriteEngine on
RewriteRule ^/(.*)$ http://www.newdomain.com/$1 [L]
</VirtualHost>

==/var/log/mod_rewrite.log:==

[www.olddomain.com/sid#8139ed4][rid#81e9064/initial] (2) init rewrite engine with requested uri /
[www.olddomain.com/sid#8139ed4][rid#81e9064/initial] (3) applying pattern '^/(.*)$' to uri '/'
[www.olddomain.com/sid#8139ed4][rid#81e9064/initial] (2) rewrite / -> http://www.newdomain.com/
[www.olddomain.com/sid#8139ed4][rid#81e9064/initial] (2) implicitly forcing redirect (rc=302) with http://www.newdomain.com/
[www.olddomain.com/sid#8139ed4][rid#81e9064/initial] (1) escaping http://www.newdomain.com/ for redirect
[www.olddomain.com/sid#8139ed4][rid#81e9064/initial] (1) redirect to http://www.newdomain.com/ [REDIRECT/302]

==Results In Error:==
==Firefox:
The page isn't redirecting properly
Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
* This problem can sometimes be caused by disabling or refusing to accept cookies.
==MSIE:
(Keeps flickering and never loads)
StupidScript
 
Posts: 5
Joined: Tue Nov 21, 2006 12:13 pm

Postby richardk » Tue Nov 21, 2006 1:01 pm

Try:
Code: Select all
<VirtualHost *>
  ServerName olddomain.com
  ServerAlias *.olddomain.com
  ServerAdmin me@olddomain.com

  DocumentRoot /usr/local/apache/sites/olddomain
  Options +FollowSymLinks

  ErrorDocument 404 http://www.olddomain.com/
  ErrorLog logs/error_old.log

  RewriteEngine On
  RewriteRule .* http://www.newdomain.com%{REQUEST_URI} [R=301,L]
</VirtualHost>

Clear your browser's cache before trying it. But there's nothing that should be causing that. Make sure you don't have any redirects back to the old domain.

To be honest, all you should really need is
Code: Select all
<VirtualHost *>
  ServerName olddomain.com
  ServerAlias *.olddomain.com
  Redirect 301 / http://www.newdomain.com/
</VirtualHost>
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby StupidScript » Tue Nov 21, 2006 1:22 pm

Yeesh!
Code: Select all
<VirtualHost *>
  ServerName olddomain.com
  ServerAlias *.olddomain.com
  Redirect 301 / http://www.newdomain.com/
</VirtualHost>
works fine. LOL! Thanks a lot for getting my head out of overkill mode.
StupidScript
 
Posts: 5
Joined: Tue Nov 21, 2006 12:13 pm

Postby StupidScript » Wed Nov 22, 2006 2:00 pm

But ... so I can get on with the learnin' ... my original
Code: Select all
RewriteRule ^/(.*)$ http://www.newdomain.com/$1 [L]


I figured this said:

Match => [^] start of string + / + capture(any char [.]/quantity [*]) => [$] end of string

Replace => [URL /] + (capture) => [L] end rewrite process

Figuring it would match:

http ://www.olddomain.com/somefile.html

and redirect to:

http ://www.newdomain.com/somefile.html where (index.html) is captured.

Does this create a loop condition, given the other httpd.conf settings in my first post?
Or, why else would the browsers return the errors (or error-ish behavior) that they did?
StupidScript
 
Posts: 5
Joined: Tue Nov 21, 2006 12:13 pm

Postby richardk » Wed Nov 22, 2006 3:29 pm

It shouldn't cause a loop. It should redirect to the new domain and never run the mod_rewrite code again. It worked fine when i tried it.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby StupidScript » Fri Nov 24, 2006 9:21 am

Thanks for that. I thought my "regex-vision" was developing cataracts!

What are your thoughts about the errors I received? Do you think these httpd.conf settings had something to do with them?
Code: Select all
UseCanonicalName On
NameVirtualHost *


I appreciate your continuing help, as I figure it might be important for me to understand, one day.
StupidScript
 
Posts: 5
Joined: Tue Nov 21, 2006 12:13 pm

Postby richardk » Fri Nov 24, 2006 10:55 am

No. I doubt that those settings could affect it.

The mod_rewrite is inside the <VirtualHost> block that will only be run for olddomain.com and *.olddomain.com. It should never match any other domain.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 17 guests

cron