1

I would like to learn if I can serve the website from 2 different versions according to URL string parameters.

Example:

  • I have two installs on my server: example.com/website-1/ and example.com/website-2/
  • if end-user visits example.com/main/?showads=yes —> serve website from example.com/website-1/
  • İf end-user visits domain example.com/main/ —> serve website from example.com/website-2/

Note: this is not a redirection question, I just want to serve with the same URL.

p.s. I'm running a WordPress website on an Apache server.

I'm open to any solution via PHP, WordPress, or Apache (.htaccess) config.

MrWhite
  • 12,647
  • 4
  • 29
  • 41
Buffy
  • 11
  • 1

1 Answers1

0

You can perform the necessary internal rewrite at the top of your root .htaccess file. For example:

RewriteEngine On

RewriteCond %{QUERY_STRING} ^showads=yes$
RewriteRule ^main/$ /website-1/index.php [L]

RewriteCond %{QUERY_STRING} ^$
RewriteRule ^main/$ /website-2/index.php [L]

If the user requests /main/?showads=yes (exactly as stated) then the request is routed to the WordPress install in /website-1/ and if the user requests /main/ (exactly - no query string) then the request is routed to the WP install in /website-2/. (NB: You should rewrite directly to index.php, rather than let mod_dir issue a secondary internal subrequest.)

HOWEVER, since this is WordPress, WP itself also needs to be configured to accept requests to /main/ in both of the websites (ie. this must be a valid URL in WP), otherwise, WP will trigger a 404.

You may consider asking this question over on the WordPress stack for more assistance with the WP side of this.

MrWhite
  • 12,647
  • 4
  • 29
  • 41