Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 226
  • Last Modified:

redirect using mod_rewrite

I have two domains hosted from the same server. I'm trying to use mod_rewrite to send requests for www.foo.com to www.bar.com, but i want to maintain www.foo.com in the browser's address field.

So far, I can do the redirect, but I haven't figured out how to retain the original url in the browser. Ideas?
0
dalelum
Asked:
dalelum
1 Solution
 
samriCommented:
dalelum,

To my knowledge, mod_rewrite will change the location url (in the location bar) as well.  If you plan to have the request to be forwarded to a remote server while maintaining the namespace to your web server, I would believe that you could you mod_proxy for that.

http://httpd.apache.org/docs/mod/mod_proxy.html

http://httpd.apache.org/docs/mod/mod_proxy.html#proxypass
http://httpd.apache.org/docs/mod/mod_proxy.html#proxypassreverse

Or maybe you could use proxy pass-through feature [P],

http://httpd.apache.org/docs/mod/mod_rewrite.html#RewriteRule

---excerpt from Apache website documentation.

'proxy|P' (force proxy)
This flag forces the substitution part to be internally forced as a proxy request and immediately (i.e., rewriting rule processing stops here) put through the proxy module. You have to make sure that the substitution string is a valid URI (e.g., typically starting with http://hostname) which can be handled by the Apache proxy module. If not you get an error from the proxy module. Use this flag to achieve a more powerful implementation of the ProxyPass directive, to map some remote stuff into the namespace of the local server.
Notice: To use this functionality make sure you have the proxy module compiled into your Apache server program. If you don't know please check whether mod_proxy.c is part of the ``httpd -l'' output. If yes, this functionality is available to mod_rewrite. If not, then you first have to rebuild the ``httpd'' program with mod_proxy enabled.
---
0
 
JOligarioCommented:
why not use a simple frame?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
     <META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
     <TITLE>foo.com.com</TITLE>
</HEAD>
<FRAMESET rows="100%,*" border=0 frameborder=0 framespacing=0>
     <FRAME name=top src="http://bar.com" noresize>
</FRAMESET>
</HTML>
0
 
BigRatCommented:
I would have though that mod-rewrite to simply rewrite the url depending on the host would work. See the rewrite example Virtual User Hosts at http://httpd.apache.org/docs/misc/rewriteguide.html

Note that the example does not do a redirect! ([R] option)

HTH

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
samriCommented:
any luck on this?
0
 
CaiapfasCommented:
I would use a 301 redirect in the .htaccess file for that diorectory
0
 
VenabiliCommented:
Caiapfas ,

This question is older than a year...The Asker is obviously not around that's why we should close it... Adding any comments cannot bring you any points...
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now