ConquerThis
New Pleskian
Apparently I can't use Markdown and it took me longer than 5 minutes to convert it to BBCode lol. Let's try again...
I have this code (which works) in Plesk in Customers > Some Customer Name > new-domain.com > Hosting & DNS > Apache & nginx Settings > Additional Apache directives (for both HTTP + HTTPS):
This means that the website can be accessed via new-domain.com, and it will display the content from old-domain.com, whilst keeping new-domain.com in the browser's address bar.
All of the relative URLs in the website's HTML work perfectly, however there are thousands of absolute URLs in the HTML too - and clicking any of them changes the URL in the address bar to old-domain.com.
I would like to use
But it appears to be having no effect - the HTML does not change.
How can I replace the domain in absolute URLs, when using a proxy, in Plesk?
I have confirmed with
The proxy works perfectly but no matter what I try, I can't get substitution or URL maps to have any effect.
I don't see any entries in the log relating to either module.
I am running the latest version of Plesk (Plesk Obsidian Web Pro Edition, Version 18.0.64 Update #1).
I am running Apache httpd
I have this code (which works) in Plesk in Customers > Some Customer Name > new-domain.com > Hosting & DNS > Apache & nginx Settings > Additional Apache directives (for both HTTP + HTTPS):
Code:
ProxyRequests On
SSLProxyEngine On
ProxyPass / https://old-domain.com/
ProxyPassReverse / old-domain.com/
This means that the website can be accessed via new-domain.com, and it will display the content from old-domain.com, whilst keeping new-domain.com in the browser's address bar.
All of the relative URLs in the website's HTML work perfectly, however there are thousands of absolute URLs in the HTML too - and clicking any of them changes the URL in the address bar to old-domain.com.
I would like to use
mod_substitute
to do a find & replace in the HTML. I tried adding this on a new line below the code above:
Code:
Substitute "s/old-domain.com/new-domain.com/ni"
But it appears to be having no effect - the HTML does not change.
How can I replace the domain in absolute URLs, when using a proxy, in Plesk?
Tried
- Removing the
"
either side of the string - Changing the delimiter from
/
to|
- Adding this above the
Substitute
line:
Code:AddOutputFilterByType SUBSTITUTE text/html
- Changing the
AddOutputFilterByType
line to:
Code:AddOutputFilterByType INFLATE;SUBSTITUTE;DEFLATE text/html
- Moving the
Substitute
+AddOutputFilterByType
lines in to a.htaccess
file in the top directory for this domain - whereindex.html
would go (keeping the proxy lines in Directives)
Also tried
- In SSH:
Code:yum install -y mod_proxy_html
- Below the Proxy lines, don't use any substitution lines and instead use:
Code:SetOutputFilter proxy-html ProxyHTMLURLMap https://old-domain.com /
- Moving these lines to a
.htaccess
(keeping the proxy lines in Directives) - Using these lines:
Code:ProxyRequests offProxyHTMLURLMap https://old-domain.com / RequestHeader unset Accept-Encoding
- Changing the
SetOutputFilter
line to:
Code:AddOutputFilterByType proxy-html text/html
- Changing the
SetOutputFilter
line to:
Code:SetOutputFilter INFLATE;proxy-html;DEFLATE
Checks
I have checked in Tools & Settings > Apache Web Server Settings, that the following Apache modules are enabled:proxy_html
, proxy_http
, substitute
.I have confirmed with
httpd -M | grep substitute
and httpd -M | grep proxy_html
that the modules are enabled.The proxy works perfectly but no matter what I try, I can't get substitution or URL maps to have any effect.
I don't see any entries in the log relating to either module.
I am running the latest version of Plesk (Plesk Obsidian Web Pro Edition, Version 18.0.64 Update #1).
I am running Apache httpd
2.4.37-65.module_el8.10.0+3874+c2064c23.2
.Apache's docs
- From mod_substitute:
A common use scenario for mod_substitute is the situation in which a front-end server proxies requests to a back-end server which returns HTML with hard-coded embedded URLs that refer to the back-end server. - From mod_proxy:
Apache httpd will not rewrite URL references inside HTML pages. This means that if the proxied content contains absolute URL references, they will bypass the proxy. To rewrite HTML content to match the proxy, you must load and enable mod_proxy_html. - From Mapping URLs to Filesystem Locations:
Links inside the documents will not be rewritten. So any absolute links on internal.example.com will result in the client breaking out of the proxy server and requesting directly from internal.example.com. You can modify these links (and other content) in a page as it is being served to the client using mod_substitute. For more sophisticated rewriting of links in HTML and XHTML, the mod_proxy_html module is also available. It allows you to create maps of URLs that need to be rewritten, so that complex proxying scenarios can be handled.