Forum Moderators: phranque

Message Too Old, No Replies

Apache mod rewrite URL redirect

         

cascade27

7:20 pm on Jan 11, 2010 (gmt 0)

10+ Year Member



I need to find a way to redirect permanently a defunct website to a completely new external website. What I'm trying to do is redirect events.mydomain.com to www.new-domain.net which is hosted on a different server at a different location by a third-party company. Our main website runs on Joomla 1.5.15 and the web server runs on Apache/Windows Server 2008. Everything I tried so far did not work.

I have the mod_rewrite enabled with

LoadModule rewrite_module modules/mod_rewrite.so

I have the following code in my .htaccess.

Options +FollowSymLinks
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^events\.mydomain\.com [NC]
RewriteRule ^(.*)$ [new-domain.net...] [R=301,L]

Additional info:
Web server: Windows Server 2008
Apache 2.2.13
Joomla 1.5.15
events.mydomain.com and our main Joomla website (www.mydomain.com) have different IP addresses.

events.mudomain.com is now defunct and we cannot afford to keep it up on the server. We need to make room for something else. So, I have to find a way to redirect all requests for events.mydomain.com (which is most likely triggered by bookmarks) to the new site address of www.new-domain.net. Any insights would be greatly appreciated. Thank you.

jdMorgan

10:55 pm on Jan 11, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



*How* specifically, does this code not work? Does the server throw an error, and if so, what's in the server error log? Or does the code just sit there silently and do nothing?

Also, be sure to completely flush (delete) your browser cache after changing any server config code like this.

Jim

cascade27

4:02 pm on Jan 12, 2010 (gmt 0)

10+ Year Member



I get the following error :

"Unable to connect
Firefox can't establish a connection to the server at events.mydomain.com."

It looks like it is trying to reach events.mydomain.com but since the website is taken down, it cannot make the connection. That means my mod rewrite is not working....

cascade27

4:10 pm on Jan 12, 2010 (gmt 0)

10+ Year Member



As for the error log, there is no error. I restarted Apache and that's recorded as shown below but nothing else.

[Tue Jan 12 07:53:27 2010] [notice] Parent: Received shutdown signal -- Shutting down the server.
[Tue Jan 12 07:53:27 2010] [notice] Child 2324: Exit event signaled. Child process is ending.
[Tue Jan 12 07:53:28 2010] [notice] Child 2324: Released the start mutex
[Tue Jan 12 07:53:29 2010] [notice] Child 2324: All worker threads have exited.
[Tue Jan 12 07:53:29 2010] [notice] Child 2324: Child process is exiting
[Tue Jan 12 07:53:29 2010] [notice] Parent: Child process exited successfully.
[Tue Jan 12 07:53:29 2010] [notice] Apache/2.2.13 (Win32) configured -- resuming normal operations
[Tue Jan 12 07:53:29 2010] [notice] Server built: Aug 6 2009 15:50:50
[Tue Jan 12 07:53:29 2010] [notice] Parent: Created child process 2904
[Tue Jan 12 07:53:30 2010] [notice] Child 2904: Child process is running
[Tue Jan 12 07:53:30 2010] [notice] Child 2904: Acquired the start mutex.
[Tue Jan 12 07:53:30 2010] [notice] Child 2904: Starting 64 worker threads.
[Tue Jan 12 07:53:30 2010] [notice] Child 2904: Starting thread to listen on port 80.

jdMorgan

4:35 pm on Jan 12, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If the DNS record for the old domain doesn't point to an active server, then nothing you do any any server is going to work.

You'll need a "A record" in the DNS zone file for the server, defining the IP address to which requests for "events.example.com." are to be routed. This should be the server that you're putting your redirect code on.

The next step is to be sure that the server to which the requests are routed will recognize requests for the "events" subdomain. If it isn't defined, you'll likely see 404 Errors in the browser, but nothing in the server logs, because the server doesn't know which host it should log the error on.

In order to do this redirect, you have to 'host' the old domain somewhere -- whether or not there are actually any 'pages' on the server.

So it sound like maybe you've jumped straight to coding, but don't have a host configured to accept the requests for the old site and run the redirect code.

Jim

cascade27

4:57 pm on Jan 12, 2010 (gmt 0)

10+ Year Member



Hi jdMorgan, thank you for your quick response. So, if the host is configured properly, my mod-rewrite code should work? There is nothing wrong with the code itself?

jdMorgan

11:05 pm on Jan 12, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The only thing wrong with it is that the back-reference token is missing, but this won't cause a DNS resolution failure.

The rule should be:


RewriteRule ^(.*)$ http://www.new-example.com[b]/$1[/b] [R=301,L]

Jim

cascade27

11:56 pm on Jan 12, 2010 (gmt 0)

10+ Year Member



Thank you for the correction, Jim. I was eventually able to solve the problem using virtual host configurations with redirect. Thank you again for your assistance.