Can Apache (or Nginx) allow 2 apps to selectively serve the same URLs?

Say I have a PHP app (WordPress) at http://example.com/.

It is not a simple blog. It is a large app with thousands of pages, multiple custom post types and “themes within a theme” to handle all of the custom content.

Read More

I want to integrate this with another PHP app (for this example let’s say silverstripe, but it could be anything) in a way that will allow me to replace things in stages because I don’t want to have to wait months until a totally new app is finished before deploying anything.

The problem is that this is a 10yr+ old site and has many legacy URLs that must be maintained. That means redirects are not allowed(for certain URLs) and I need either app to be able to respond to the same URLs that currently exist. Can’t add in /wp/ or anything like that. The URLs need to be identical.

So for instance we currently have a page at http://example.com/page.html that is being generated by WordPress. I would like to replace this with a page that is generated by silverstripe.

Is there a way to configure Apache or Nginx so that if the silverstripe app understands the request (has a route defined) for http://example.com/page.html it will be generated by silverstripe and if it doesn’t understand the request it will “fall back” to WordPress and be served from the same URL http://example.com/page.html by WordPress. Not http://example.com/wordpress/page.html

Thanks!

Related posts

Leave a Reply

1 comment

  1. Apache mod_rewrite‘s “passthrough” can handle this. It’s frequently used for URL shortening for SEO purposes (e.g. to rewrite /some/crazily/long/path to /short), and could also be used by you to use /page.html as /wordpress/page.html, e.g:

    RewriteRule ^/page.html$ /wordpress/page.html [PT]
    

    So go ahead and setup the separate directory for your wordpress instance, and use RewriteRule. The URL will still show up as ‘/page.html’ in the brower’s location bar, but it will serve ‘/wordpress/page.html’.

    More on PT: http://httpd.apache.org/docs/2.4/rewrite/flags.html#flag_pt

    This will take care of your ‘served from same URL’ requirement. As far as serving it only if you can’t serve it from the first app, take a look at this existing thread: Redirect requests only if the file is not found?