Steve Robinson
Steve Robinson

Reputation: 3939

Serve content from external server via apache

I am running my web app at abc.com with apache as the web server.

I have some static pages hosted on SquareSpace... eg. abc.squarespace.com/landing

I want to configure apache to serve content from abc.squarespace.com when it get's a request for abc.com/landing

I've done this in nginx by using proxy_pass with the backend as abc.squarespace.com for location /landing. But I'm not sure how to do this in Apache. No luck doing research on the web as well.

Thanks in advance.

Upvotes: 7

Views: 1329

Answers (2)

Sandeep Nair
Sandeep Nair

Reputation: 357

Not sure whether ask was for a redirection to abc.squarespace.com or proxy the call internally, here are the solutions for both

Redirection : browser will hit abc.com/landing and get a 301 redirect which changes url changes to abc.squarespace.com/landing

Add rule to httd.conf or included vhost file :

RewriteEngine on
RewriteRule   "^/landing/(.+)"  "http://abc.squarespace.com/landing/$1"  [R,L]

Proxy : the abc.squarespace.com under abc.com > browser will not no that the page is served from any downstream domain.

Option 1: Use a rewrite rule with P(proxy) switch

RewriteEngine on
RewriteRule   "^/landing/(.+)"  "http://abc.squarespace.com/landing/$1"  [P]

Option 2: Use a proxypass

ProxyPass "/landing" "http://abc.squarespace.com/landing"
ProxyPassReverse "/landing" "http://abc.squarespace.com/landing"

Additionally, timeout can be specified if needed and also a ProxyRemote can be configured if routing over any internet proxy is needed

Good References

Upvotes: 1

Elvis Plesky
Elvis Plesky

Reputation: 3300

Message body cannot contain URLs with abc.com, so I will be using example.com and example.squarespace.com.

I believe you are looking for frame forwarding. In order to implement it, use the following steps:

  1. On example.squarespace.com allow frame forwarding from example.com by setting the appropriate HTTP headers via web server configuration:

X-Frame-Options: ALLOW-FROM https://example.com/

For detailed explanation refer to https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options

  1. Verify that Apache mod_proxy_http is enabled at example.com:

# apachectl -M | grep proxy_http proxy_http_module (shared)

  1. Set the following rewrite rules in Apache configuration or .htaccess file to serve content from http://example.squarespace.com/landing

<IfModule proxy_http_module> RewriteEngine On RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC] RewriteRule ^landing(.*) http://example.squarespace.com/landing [P] </IfModule>

The syntax here is the same as for Apache mod_rewrite.

Upvotes: 2

Related Questions