Web Hosting Talk







View Full Version : Help with mod_rewrite rule


sdnet
08-01-2006, 08:44 PM
I hope this is the right forum to post this. I'm looking for some help writing a mod_rewrite rule that redirects all users from a domain to an IP address. So, if you enter the following URL:

http://www.somedomain.com

The server will call:

http://111.111.111.1111/sites/somedomain.com

And, if you enter the following URL:

http://www.somedomain.com/dir/page.html

The server will call:

http://111.111.111.1111/sites/somedomain.com/dir/page.html

I know this is possible, but I'm not sure of how the re_write rule is structured.

Thanks.

ThatScriptGuy
08-02-2006, 10:23 AM
RewriteEngine On
Options +FollowSymlinks
RewriteCond %{HTTP_HOST} ^(www\.)?somedomain\.com$ [NC]
RewriteRule ^ http://111.111.111.111 [R,L]

Save it for future use (It comes in handy)
Kevin

sdnet
08-02-2006, 10:32 AM
Thanks kvnband. Your code works, but the problem is it only does a simple redirection, which means the destination IP address is displayed in the browser's web address bar. What I'm looking for is a way to make the server call the IP address behind the scenes and display the page with the current somedomain.com url intact (and all folders/pages under the domain). I know about the HTML frame mechanism, but I'd like to avoid that if at all possible. I'd like to be able to specify a particular page within the domain name and have it redirect to that same page on the IP address-based web server.

Is that possible?

ThatScriptGuy
08-02-2006, 10:46 AM
If you've got mod_proxy installed, then change the L to a P or maybe it's change [R,L] to just [P]....I know you have to change the L to a P but I've forgotten about if the R stays or goes...

In explanation, you have to use mod_proxy because you are in essence going to a different site, which will always show the new address in the bar. A work around is to do so via mod_proxy (using the P flag)
Kevin