3

I am using Docusaurus to provide a User Manual for a web app that is hosted on an AWS EC2 virtual server. The user accesses it through a button on the app. I am trying to set it up so that it will run on three sites without additional configuration (i.e. I just want to pull the code from GitHub to each of the sites without making individual site changes). The three sites are:

  1. localhost/prsm/doc/help/
  2. exampledev.com/prsm/doc/help/
  3. example.com/doc/help/ -- note no prsm directory for this one

I have set the baseUrl in docusaurus.config.js to /prsm/doc/help/ and all works well for the first two sites, but results in a '404 not found' error on site 3. I wondered about using an apache RewriteRule in an .htaccess file on site 3, but can't work out what the rule should be. Or is there an alternative way of getting it to work on site 3? (Putting the app in a prsm subdirectory is not an option, because the URL for site 3 is already well known to users and they will be confused if it changes).

Nigel
  • 585
  • 1
  • 5
  • 20
  • "but can't work out what the rule should be" - It would be helpful to see what you have tried (and what the result was) as this could highlight other issues that need to be addressed. – MrWhite Feb 21 '23 at 13:41

1 Answers1

1

It sounds as if you just need to remove (via an internal rewrite) the /prsm path segment (that is presumably present in the URLs generated by Docusaurus) if requested on the example.com host.

For example, assuming this is Apache, then you can use mod_rewrite in the root .htaccess file:

RewriteEngine On

RewriteCond %{HTTP_HOST} =example.com [NC]
RewriteRule ^prsm/(doc/help/.*) $1 [L]

Any HTTP request to /prsm/doc/help/<anything> is rewritten to doc/help/<anything> (the value of the $1 backreference). Note that this does not "change" URLs. The user will still see the /prsm prefix in the URL.

Note that the URL-path matched by the RewriteRule pattern does not start with a slash.


I have set the baseUrl in docusaurus.config.js to /prsm/doc/help/

I'm not familiar with Docusaurus, but if this is set in client-side JS then can't it be set conditionally based on the window.location.hostname property?

MrWhite
  • 43,179
  • 8
  • 60
  • 84
  • 1
    I'll try this .htaccess code and report back. Docusaurus is a static site generator, and all the links are baked in at the time of generation. So client side changes to docusaurus.config.js wouldn't work. – Nigel Feb 22 '23 at 11:24