Jump to content
  • Advertisement
Sign in to follow this  
BeanDog

[web] mod_rewrite with proxy to another domain on the same physical server

This topic is 4434 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Well, the title says most of it. I'm using mod_rewrite to map some stuff from one of our sites into another of our sites. Both sites are hosted on the same physical server. So, consider the following line in the .htaccess file of the server I want to use as a proxy: RewriteRule somepage.htm http://www.site_b.com/dir/script.php?page=somepage

This is, of course, a simplified trivial example. On one site, the user requests an HTML file, the content of which I serve up via a script on another domain. If I remove the

from the rule, making it redirect instead of proxy, this works correctly but displays the mangled URL to the user in their browser. If I leave the

in, I get a 404 error. I assume the 404 error is because the

flag is invalid if you're redirecting to the same server (source), and my sites are hosted on the same physical server. This is basically a guess, though. Any hints?

Share this post


Link to post
Share on other sites
Advertisement
IIRC if you rewrite to leave off the

flag and rewrite to a local directory instead of an URL (possible, since it's all on the same server) then you won't see the mangled URL.

Share this post


Link to post
Share on other sites
Unfortunately, the user account for one domain has no access rights to the other domain's files.

Share this post


Link to post
Share on other sites
Quote:
Original post by Sander
That shouldn't matter, as long as Apache has access to both.

How would I redirect to a hard file path? Something like this I assume:

RewriteRule ^((.*)/)?([^\./]*)\.htm(l)? /home/othersite/public_html/master.php?URI=%{REQUEST_URI}&Server=%{SERVER_NAME}

This doesn't work, because it sees the path as a local URI and tries to redirect to www.thissite.com/home/othersite/public_html/master.php instead of www.othersite/master.php.

Share this post


Link to post
Share on other sites
Have a look at the RewriteBase option. From the apache docs, it looks like it should do the trick, but the docs are pretty sparse on examples (especially in combination with virtual hosts).

Also note that it makes a difference wether the rewrite rules are in the httpd.conf or in a .htaccess file (according to the mod_rewrite docs).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!