Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mod-rewrite rule for external pages?

Is it possible use mod_rewrite to resolve addresses hosted on another server?

Say I want to setup this URL:

http://www.myserver.com/myfolder/

To actually resolve to:

http://www.anotherserver.com/anotherfolder/

If so, could you provide a RewriteRule example?

like image 818
sthg Avatar asked Nov 09 '09 09:11

sthg


People also ask

What is $1 rewrite rule?

In your rewrite, the ^ signifies the start of the string, the (. *) says to match anything, and the $ signifies the end of the string. So, basically, it's saying grab everything from the start to the end of the string and assign that value to $1.

What is RewriteRule * F?

RewriteRule "\.exe" "-" [F] This example uses the "-" syntax for the rewrite target, which means that the requested URI is not modified. There's no reason to rewrite to another URI, if you're going to forbid the request.

How do you write rewrite rules in httpd conf?

A rewrite rule can be invoked in httpd. conf or in . htaccess . The path generated by a rewrite rule can include a query string, or can lead to internal sub-processing, external request redirection, or internal proxy throughput.


1 Answers

You can use the P flag in a mod_rewrite rule to get that substitution URL requested by mod_proxy:

RewriteEngine on
RewriteRule ^myfolder/$ http://other.example.com/anotherfolder/ [P]

Now when a client is requesting /myfolder/ from your server, it will request http://other.example.com/anotherfolder/ and send the response from that server back to the client.

like image 100
Gumbo Avatar answered Oct 21 '22 05:10

Gumbo