We currently have a bunch of ASP.NET applications which are all accessible through one domain. So www.example.com connects to the main website. www.example.com/documents is a separate application allows customers to access their documents.

This is hosted in IIS with the documents branch being an ASP.NET application. Customers have emails that link to their documents like: www.example.com/documents/document?id=12345

We're looking at updating the main website and separating it from everything else - moving it to a separate host - most likely an Apache/WordPress setup.

With this in mind the original domain name would go with the main website, and then a secondary domain would be setup which would continue to hold the documents application on Windows/IIS. www.backenddomain.example/documents

In this scenario is it possible for Apache/WordPress to redirect just the documents sub folder/page to the new domain without the URL changing in the browser? So www.example.com/documents goes to www.backenddomain.example/documents but the customers sees www.example.com/documents

I know I can setup a 301 redirect but that changes the URL the customer is presented and ideally I'd prefer it if we can keep it the same. Effectively forwarding the content.

  • 3
    Redirects always change the URL. Rewrites show different content at a URL within the same server. A reverse proxy shows content from another server at a URL. If you know the correct terminology, you will be able to search for what you need easily. Commented Nov 7, 2018 at 12:49
  • Thanks Stephen - I had a good play with the reverse proxy idea. In the end I realised Jeremy's solution was actually what I needed. Commented Nov 8, 2018 at 12:30

1 Answer 1


Too bad you didn't use documents.example.com because then you could get the effect you want although you will still have to change the URL.

Even with masking, you could not point to a different URL without redirecting the user the the URL. Think about the security risks that are involved here. The potential for abuse is so high this isn't even allowed, and for good reason. If you are pointing someone to a new domain, you must expose that domain. (there are ways to bypass this but that is considered blackhat/greyhat and I caution using these methods)

An alternative approach would be to create the sub-domain: documents.example.com and point that to the old server.

Then on the new server, you can use some regex logic to redirect for the legacy document URLs to the new sub-domain URL (which is pointing to the old server)

RewriteRule ^/?documents/(.*) http://documents.example.com/$0 [R,L]

That will allow any of the existing URLs to be redirected to the new sub-domain. Which is still the effect you are looking for. Albeit this is using a sub-domain.

On the old server you can handle the requests to force this domain to be restricted to the documents folder. Although I would suggest you configure the host to be the documents directory instead of this hack.

RewriteCond %{HTTP_HOST} documents.example.com
RewriteCond %{REQUEST_URI} !^/?documents/
RewriteRule .* documents/$0

Using this approach, you should be able to have the appearance you want. I would still suggest you update the app to use the new URL but that is not necessary as the redirect will handle that for you.

While this does not allow you to have the functionality you want without changing the URL, this does allow the URL change to be handled VIA redirects and host config instead of having to modify the app code. This will have minimal impact and is a very quick solution to the problem at hand. This setup will allow you to redirect the legacy URLs to the new sub-domain that is pointing to the documents directory. I would encourage the use of cookies/tokens to ensure that users access these documents are allowed but that's outside the scope of this question.

  • 1
    Thanks Jeremy I like this solution and is what I'm looking at going with - new sub domains would look more professional thinking about it and we'll change them over for new emails. I'm not sure that the reverse proxy idea suggested by Stephen Ostermiller would be considered blackhat though? There are multiple layers of security on the documents side of things already I just simplified it for the question. Commented Nov 8, 2018 at 12:29
  • 1
    Greyhat would be a better fit for that. Basically, you are acting as a man-in-the-middle layer which is sketchy. Even if it is for your system, this approach is not something I would warrant because it's just a patch for the issue and not a long term solution. Not to mention, it's a bit overkill for what you need. While the proxy layer can be justifiable, this is also a popular method used for malicious intent. Of course there are valid reasons to use it too but as I previously stated, it's a bit overkill.
    – Jeremy
    Commented Nov 8, 2018 at 15:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.